Threading and UI Updating

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am new to Multithreading in .NET and like to seek some guidance on the
following:-

Some Background
---------------------
I wrote a Data Acquisition program (usings Sockets) that monitor and get
data from a few Industrial Machines.

I need to query their Internal Relays and Data Register for status and
progress of each Job being assigning to those machine.

Then I need to update MsSQL with the data return back from those machines.

An additional Client Browser program I wrote, will actually query the MsSQL
for the data and update the UI. At the time the client get the data, it may
be a half a minutes outdated, but it is OK.

Client Browser <----> MsSQL <----> Data Acquisition ----> Industrial Machines


My Questions:
----------------
1) How do I write a multithreading routine that can run by itself and query
the Machines every n-seconds ?

2) Since the routine to capture the data from each machine is the same, is
it neccessary to create one thread for each machine or just one single thread
for
all the machines ?

3) After I got the data, should I update my MsSQL from the UI thread or from
the worker thread ?

4) What is the best way to communicate back to my client browser, which is
an exe by itself, that the data in the MsSQL has been updated and tell it to
refresh its UI?

I am using MsSQL 2000, VB.NET 2003, XP for Client Browser, Windows Server
2003 for Data Acquisition.


Thank You,
mfwoo
 
The application has a thread going when you call your first form with
Application.Run(new Form1()).
This is the UI thread.
1. To maintain User Interface responsiveness (ex. Refresh the window, Click
on a help button etc), you need to spawn a worker thread.
2. You can have one thread for all the "machines". (In a loop in the worker
thread, you can take action when data is returned)
3. You can call SQl without any problems for anythread.
4. You cannot update Userinterface code from inside a thread. You have to do
a
control.Invoke(delegate to code refreshing routine). Where control is the UI
control calling the routine (so if this code is in the control, it is
this.invoke)

Read this before you proceed.
http://msdn.microsoft.com/msdnmag/issues/03/02/Multithreading/

HTH,
Hananiel
 
Back
Top