S
Shannon Cayze
Hello all,
In my Windows Forms app I'm opening an OpenFileDialog. This throws the
following exception because I have the MTAThread attribute on the Main
method:
"Current thread must be set to single thread apartment (STA) mode
before OLE calls can be made. Ensure that your Main function has
STAThreadAttribute marked on it. This exception is only raised if a
debugger is attached to the process."
I can't just change it to STAThread because elsewhere in the same form
I'm using the WaitHandle.WaitAll method as follows, which requires the
MTA apartment state:
// Loop while the thread has not finished
while( this.workerThread.IsAlive )
{
// Wait until the thread indicates that it has stopped.
// Only block for 100 ms so that the UI can remain responsive.
if( WaitHandle.WaitAll( stoppedEvents, 100, true ) )
break;
// Allow any events to process that occurred in
// the UI while waiting
Application.DoEvents();
}
Using the Thread.CurrentThread.SetApartmentState method when necessary
throws the following exception:
"Failed to set the specified COM apartment state."
Can anyone help me understand what I need to do so that both features
work correctly?
Thanks in advance,
Shannon
In my Windows Forms app I'm opening an OpenFileDialog. This throws the
following exception because I have the MTAThread attribute on the Main
method:
"Current thread must be set to single thread apartment (STA) mode
before OLE calls can be made. Ensure that your Main function has
STAThreadAttribute marked on it. This exception is only raised if a
debugger is attached to the process."
I can't just change it to STAThread because elsewhere in the same form
I'm using the WaitHandle.WaitAll method as follows, which requires the
MTA apartment state:
// Loop while the thread has not finished
while( this.workerThread.IsAlive )
{
// Wait until the thread indicates that it has stopped.
// Only block for 100 ms so that the UI can remain responsive.
if( WaitHandle.WaitAll( stoppedEvents, 100, true ) )
break;
// Allow any events to process that occurred in
// the UI while waiting
Application.DoEvents();
}
Using the Thread.CurrentThread.SetApartmentState method when necessary
throws the following exception:
"Failed to set the specified COM apartment state."
Can anyone help me understand what I need to do so that both features
work correctly?
Thanks in advance,
Shannon