M
Mark Huebner
I need to create a Windows application that polls a device through a serial
port and updates textboxes on a form with the data received from the device.
The polling task also needs to update a SQL Server 2005 database with the
data received from the device. This application also needs to periodically
send some data from the SQL Server database to the this device through the
same serial port. Reading from and writing to the serial port does not have
to occur simultaneously.
I first tried to do this by creating a separate thread that does the polling
but the thread doesn't have access to the components on the Windows form. I
read that it is possible to update the UI using delegates and the Invoke
method but this seemed too complicated and limiting. I was also concerned
about restrictions on what can be done in threads and that I might not be
allowed to update our SQL Server database from a secondary thread.
I then tried to create a polling loop in the form's Shown event, but the
loop freezes the form. Is there a pause-like statement I can add to my
processing loop that allows other form related processing to occur and form
events to fire? What is the best way to perform a background task in a
Windows form application and update the UI (form) from the background task?
The tool I am using is Visual Studio 2005 pro. Thanks in advance!
Mark Huebner
port and updates textboxes on a form with the data received from the device.
The polling task also needs to update a SQL Server 2005 database with the
data received from the device. This application also needs to periodically
send some data from the SQL Server database to the this device through the
same serial port. Reading from and writing to the serial port does not have
to occur simultaneously.
I first tried to do this by creating a separate thread that does the polling
but the thread doesn't have access to the components on the Windows form. I
read that it is possible to update the UI using delegates and the Invoke
method but this seemed too complicated and limiting. I was also concerned
about restrictions on what can be done in threads and that I might not be
allowed to update our SQL Server database from a secondary thread.
I then tried to create a polling loop in the form's Shown event, but the
loop freezes the form. Is there a pause-like statement I can add to my
processing loop that allows other form related processing to occur and form
events to fire? What is the best way to perform a background task in a
Windows form application and update the UI (form) from the background task?
The tool I am using is Visual Studio 2005 pro. Thanks in advance!
Mark Huebner