OPC Studio User's Guide and Reference
AssureSecurityInitializationAndRunOnStaThread Method



OpcLabs.BaseLib Assembly > OpcLabs.BaseLib.Runtime.InteropServices Namespace > ComManagement Class : AssureSecurityInitializationAndRunOnStaThread Method
The action to be run on an STA thread after the COM security is initialized.

The value of this parameter cannot be null (Nothing in Visual Basic).

Assures that COM security is initialized, and runs the specified action on an STA thread.
Syntax
'Declaration
 
Public Sub AssureSecurityInitializationAndRunOnStaThread( _
   ByVal runAction As Action(Of ValueResult(Of Boolean)) _
) 
'Usage
 
Dim instance As ComManagement
Dim runAction As Action(Of ValueResult(Of Boolean))
 
instance.AssureSecurityInitializationAndRunOnStaThread(runAction)
public void AssureSecurityInitializationAndRunOnStaThread( 
   Action<ValueResult<bool>> runAction
)
public:
void AssureSecurityInitializationAndRunOnStaThread( 
   Action<ValueResult<bool>^>^ runAction
) 

Parameters

runAction
The action to be run on an STA thread after the COM security is initialized.

The value of this parameter cannot be null (Nothing in Visual Basic).

Exceptions
ExceptionDescription

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

An error has occurred during application execution.
Thrown when there is not enough memory to continue the execution of a program.
The feature does not run on a particular platform.
Thrown when a System.Threading.Thread is interrupted while it is in a waiting state.
Remarks

This method can be used in programs that were originally designed to run on an STA thread, but had to be switched to an MTA thread in order to prevent premature COM security initialization. The method assures the COM security initialization using the AssureSecurityInitialization method, and then runs the specified runAction on an STA thread. The current thread is used, if it already is an STA thread; otherwise, a dedicated thread is created for the runAction execution, and its apartment state is set to STA. In both cases, the control returns to the caller after the runAction has completed. The runAction takes a single argument, which is the result of the COM security initialization, as returned by the AssureSecurityInitialization method call.

The runAction is executed even when the COM security initialization fails.

Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also