C
Codemonkey
Hi,
Sorry for the cross group post, but I couldn't find a group that deals with
threading in .net.
Anyway, I've noticed a difference in the way my program acts on Windows 98
than it does on WindowsXP and was wondering if anybody can explain this
behaviour.
My application runs in the background to collect data through the serial
port using a 3rd party ActiveX communications control (not MSComm). The
control is single threaded and needs a form to be hosted on. I call the
"Read" method on the control to read data and the result is returned
Asynchronously in an event called "OnReadDone".
I host the control on a hidden form that is created on an STA thread. When I
want to read data, I invoke the "ReadSync" method on the form (which I have
created to convert the Asynchronous "Read" call to a synchronous call). I
use a ManualResetEvent in the "ReadSync" method to block the thread until
the result is returned by the event.
In Windows XP, everything works fine - the "ReadSync" method blocks, the
event fires, and then the "ReadSync" method returns.
In Windows 98, the event doesn't fire until the wait on the ManualResetEvent
times out and unblocks the form's thread.
I've fixed the problem by not ever blocking the form's thread - by moving
the "ReadSync" method into the thread that invokes the "Read" method and
waiting there.
Is this behaviour by design and is Windows XP letting me do things I
shouldn't be, or is it a shortcoming in the way threads are handled under
Windows 98? Could it be something to do with the COM interop side of things
with the ActiveX control?
I'm using Visual Studio 2003 and Framework 1.1 on both machines.
I'd appreciate any thoughts on this.
Best Regards,
Trev.
Sorry for the cross group post, but I couldn't find a group that deals with
threading in .net.
Anyway, I've noticed a difference in the way my program acts on Windows 98
than it does on WindowsXP and was wondering if anybody can explain this
behaviour.
My application runs in the background to collect data through the serial
port using a 3rd party ActiveX communications control (not MSComm). The
control is single threaded and needs a form to be hosted on. I call the
"Read" method on the control to read data and the result is returned
Asynchronously in an event called "OnReadDone".
I host the control on a hidden form that is created on an STA thread. When I
want to read data, I invoke the "ReadSync" method on the form (which I have
created to convert the Asynchronous "Read" call to a synchronous call). I
use a ManualResetEvent in the "ReadSync" method to block the thread until
the result is returned by the event.
In Windows XP, everything works fine - the "ReadSync" method blocks, the
event fires, and then the "ReadSync" method returns.
In Windows 98, the event doesn't fire until the wait on the ManualResetEvent
times out and unblocks the form's thread.
I've fixed the problem by not ever blocking the form's thread - by moving
the "ReadSync" method into the thread that invokes the "Read" method and
waiting there.
Is this behaviour by design and is Windows XP letting me do things I
shouldn't be, or is it a shortcoming in the way threads are handled under
Windows 98? Could it be something to do with the COM interop side of things
with the ActiveX control?
I'm using Visual Studio 2003 and Framework 1.1 on both machines.
I'd appreciate any thoughts on this.
Best Regards,
Trev.