multithreading - C# Events firing on wrong thread -


all

i have application allows user communicate multiple serial devices. manager class used start application, creates new thread each serial device. inside thread, serial device created , thread , serial device object stored inside manager class later when needed.

the serial device class creates com port class on it's own new thread used connect com port , send / receive data. when data received event fired serial device class in turn fires event manager class, in turn fires event ui alert user new data has arrived.

my problem comes when com port class fires it's event notify serial port class, serial port class receives event , continues processing under com port thread. likewise if user sends information down com port, runs under ui thread.

i add code edit later, now, if can spot obvious greatful.

i have tried receiving event in serial device class , invoking method see if makes run under correct thread no good.

i know serial device thread running application.run inside class after it's created it's com port classes.

i'm not using background workers these threads meant exist life of application , understand background workers meant used short running calculations.

many thanks

edit:

forgot mention, winforms app in .net 2.0, no dispatcher available

edit: okay, looks information being passed inside datareceived thread (i think isn't com port thread either). tried using backgroundworker serial device class didn't make difference. help?

.net 2.0 has synchronizationcontext. it's slight pain (you have pass context ui thread others) should trick.

more info here: http://msdn.microsoft.com/en-us/magazine/gg598924.aspx


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -