![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm trying to use AsyncOperation to execute a method in a main thread context from a worker thread. If I run the program from a console application then it doesn't work. If however I run it from a WindowsForms application it does. Basically I set the name of the main thread to "Main Thread", when the "ShouldBeInMainThreadCall" is called the Thread.CurrentThread.Name is null. However if I run it in a WindowsForms application it has the correct name. Could anyone help me with this? |
#3
| |||
| |||
|
|
On Nov 19, 1:50 pm, "Lee Alexander" <lee@feedghost_dot_com> wrote: I'm trying to use AsyncOperation to execute a method in a main thread context from a worker thread. If I run the program from a console application then it doesn't work. If however I run it from a WindowsForms application it does. Basically I set the name of the main thread to "Main Thread", when the "ShouldBeInMainThreadCall" is called the Thread.CurrentThread.Name is null. However if I run it in a WindowsForms application it has the correct name. Could anyone help me with this? Console applications don't (normally, at least) run a message pump or anything similar - the main thread just runs until it's finished all its work. There's no way of getting back to the "main" thread of a console application (without extra work to basically have your own producer/consumer queue). Jon |
#4
| |||
| |||
|
|
Yeah I figured that was the case, the thing I find perplexing is the difference in behaviour, in that when run under Windows Forms the delegate gets run in the main thread SynchronizationContext whereas under the console application it runs in a seperate thread. It seems to be a recipe for problems if a component that relies on this is run within both Console and Windows Forms (message pump) scenarios. Maybe I'll add a little comment on the Community Content mentioning this.. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |