multithreading - Visual C#, Child Thread halts processing on parent thread. Why? -


i using visual c# .net via visual studio 2008 express , launching thread forms applications wait on incoming data in loop. so, each loop waits till data available, gets data, , starts again waiting.

the main reason why i'm waiting data in separate thread form still allow interaction while other sits there waiting data.

for whatever reason, form lock while other thread waiting.

unfortunately, forced use proprietary function acquire data. processing literally stop @ function till data returned (which waits on hardware inputs). so, user can click in vain on menu options no effect, till child thread returns data , clicked menu options change status , lock again.

so, question is:
why child thread holding form? isn't supposed independent? can force form continue function if child thread waiting on something?

i making thread this:

controlthread = new thread(new threadstart(run)); controlthread.start(); 

where run function this:

public void run() {     while (!stopeventhandle.waitone(0, true))     {         int data = waitfordata();         invoke(delegatedresults);     } } 

where delegatedresults function on form updates textboxes using data came in.

i forced use proprietary function acquire data

you didn't function. problem suggests implemented com server, pretty common. com takes care of threading requirements com server. such server indicates in registry threadingmodel registry key kind of threading supports. very common setting "apartment", default when key missing.

that setting indicates server doesn't support threading. needs single threaded apartment (sta). com takes care of , automatically marshals call made on server sta thread. ui thread. goes dead doornail until call completes.

there ought in documentation library. contacting vendor support idea well. if can't first thing try initializing server on worker thread instead of ui thread. solve problem if threadmodel "both". if doesn't you'll need create own sta thread. call thread.setapartmentstate() before starting thread, start own message loop application.run() in thread. might able skip loop required.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -