G
Geoff Callaghan
I have an application that is used to control a hardware device through an
RS232 port. I send a command, the hardware responds with a command. There is
also a GUI involved which cannot be frozen while I wait for a response from
the hardware. To achieve this, I use a WaitFor type structure (I'm using a
third party COM control) that allows me to send a command and wait a
specific number of milliseconds until I see one of several responses.
This all works reasonably well for a few minutes. Eventually, however, I get
a null reference exception, and I don't really know where it is coming from.
The commands I send are sent from a threadpool object, which then waits for
a timeout or a response before exiting. There are never more than a few
running at any given time (assuming that the thread exits when the delegate
function is finished, which is how I understand it). The error appears to
happen when the
responses come in.
Am I supposed to explicitly dispose of the threadpoll object, or anything
related? I'm not very familiar with how Visual Basic .NET deals with
threads, and all the blogs and articles I can find are somewhat unclear.
Also, since the thread is using the com object, and the com object is also
being used outside the thread for receiving data, is there a conflict here?
If so, I'm not sure how I would get around it.
RS232 port. I send a command, the hardware responds with a command. There is
also a GUI involved which cannot be frozen while I wait for a response from
the hardware. To achieve this, I use a WaitFor type structure (I'm using a
third party COM control) that allows me to send a command and wait a
specific number of milliseconds until I see one of several responses.
This all works reasonably well for a few minutes. Eventually, however, I get
a null reference exception, and I don't really know where it is coming from.
The commands I send are sent from a threadpool object, which then waits for
a timeout or a response before exiting. There are never more than a few
running at any given time (assuming that the thread exits when the delegate
function is finished, which is how I understand it). The error appears to
happen when the
responses come in.
Am I supposed to explicitly dispose of the threadpoll object, or anything
related? I'm not very familiar with how Visual Basic .NET deals with
threads, and all the blogs and articles I can find are somewhat unclear.
Also, since the thread is using the com object, and the com object is also
being used outside the thread for receiving data, is there a conflict here?
If so, I'm not sure how I would get around it.