From: Willy Denoyette [MVP] on
The STAThread attribute on Main initializes the main thread to enter a
Single Threaded Apartment (STA). STA threads need a message queue to
synchronize it's accesses, if a thread doesn't run a message queue when it
enters the STA, COM will create one on your behalf, but it's up to your code
to pump the messages. Now, without STAThread, the thread remains
uninitialized or enters the MTA and no queue gets created, effectively
removing the requirement for "pumping". That's why you won't see the MDA
again.

Willy.


"OldButStillLearning" <OldButStillLearning(a)discussions.microsoft.com> wrote
in message news:FF1F78B3-42A6-4398-ABA9-B9535DF46F5A(a)microsoft.com...
|I am using the Oracle drivers (Oracle.DatabaseAccess) and not the Microsoft
| version of the Oracle drivers.
| Yes, my "Main" method had the "[STAThread]" and I removed it as you
| suggested. I had already modified my program to create a thread for the
| process which is reading and looping through the database, and I can not
tell
| any longer if you believe that is or is not necessary. It almost sound
like
| you think the removal of the "[STAThread]" is going to do the trick. I
have
| been wanting to learn more about threading as it is something that I have
a
| need for in other processes, even if it turns out I do not need it here.
|
| So by taking off the "[STAThread]", the system no longer is checking the
| "pump" period? Is that the gist of what is occuring?
|
| My test ran successfully and was not been interupted by the
| "ContextSwitchDeadlock" error message, so it would appear that the issue
is
| resolved, but I'm not sure which action resolved it, changing the process
to
| run on its' own thread or removing the "[STAThread]", but I suspect that
it
| was the ""[STAThread]" change.
|
| Again, thanks SOO MUCH FOR YOUR HELP!!!!!!
|


From: OldButStillLearning on
OK, I thought the IDE generated the "STAThread" when it created the class for
me, but maybe not, because I have done a lot of maintenance on it and perhaps
I copied something from another class. I can't say for sure.

So what is a message que and when do I need one, as I apparently do not need
one in this instance.....


From: Andy on
The message queue (I believe) is how windows tells your application
which events are raised. So your application may get a messge asking
it to refresh, handle a user click event, etc. While you are working
in the main thread, your UI can't respond to those events until your
code completes. Build a windows forms application, and add a button to
a form. IN the button click handler, add a
System.Threading.Thread.CurrentThread.Sleep( 10000 ) call. Then try to
move the form or drag another window over it, and notice it doesn't
repaint. Eventually the thread will 'wake up' and handle the events
(Paint, Move, etc). Unless you explicitly create another thread,
you're always working on the main thread.

Sounds like using the STAThread attribute will automatically create a
message queue (aka message pump) on the main thread.

Working with threads is fairly easy, but can also be easy to mess up.
If you're doing a Windows form application you probably will want to
use the BackgroundWorkerProcess component. It will handle a background
thread so that your UI can continue to update smoothly. It works by
creating an event handler for the components DoWork event. The code in
here is the code that will actually execute on a background thread. In
the DoWork event handler, you can raise another event to report
progress back to your ui. The UI will remain responsive instead of
blocking using this component.