473,326 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

continuously running thread?

Hello:
I have 2 windows application 1st one is periodically writing specific data
to XML file , the 2nd application has a dialog with DataGrid , the datagrid
filled with information in the XML generated by 1st application and should
be updated as soon as the XML file is update, so I decide to code a
continously running thread that checks the XML every specific time and
refresh the contents of datagrid
the question :
1. How can I code a thread that continously checks the XML after specific
time.

Best Regards
Nov 16 '05 #1
2 7730
Don't create your own thread, use the CLR threadpool via the System.Threading.Timer class. This will fire a method at a timed interval on a threadpool thread and this method can check the XML file.

However, be careful in that you sound as if you then want to update the user interface when the XML file has changed. You will need to call Control.BeginInvoke on one of the controls on the form (the datagrid itself would work well) and pass it a method you want executed on the UI thread that will perform the datagrid refresh. This is because only the UI thread is allowed to update the UI in any way.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

Hello:
I have 2 windows application 1st one is periodically writing specific data
to XML file , the 2nd application has a dialog with DataGrid , the datagrid
filled with information in the XML generated by 1st application and should
be updated as soon as the XML file is update, so I decide to code a
continously running thread that checks the XML every specific time and
refresh the contents of datagrid
the question :
1. How can I code a thread that continously checks the XML after specific
time.

Best Regards
Nov 16 '05 #2
Be aware that the timer classes may end up consuming more than one thread... If
your working process takes a sufficiently
long amount of time, longer than the check interval, then you'll wind up with
multiple threads queued to read from the same
file. These types of concurrency issues are easier to avoid with your own
thread, and continuously running threads aren't
a negative thing or difficult to create. In addition with multiple threads that
can be doing the same work, some concurrency
constructs have to be put into place to avoid them walking on the same data
structure (if you are using shared data structures).

[pseudo-C#]
Thread thread = new Thread(new ThreadStart(Thread_ContinuousChecker));
thread.IsBackground = true;
thread.Name = "Data Polling Thread"; // <-- Useful for debugging, way more than
a worker pool thread.
thread.Start();

private void Thread_ContinuousChecker() {
while(true) {
// Do your checking
if ( newData ) { Process(); BeginInvoke(UpdateGUI); }
Thread.Sleep(/* milliseconds to wait */ 5000); // Check every 5 seconds.
}
}
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Richard Blewett [DevelopMentor]" <ri******@develop.com> wrote in message
news:e8*************@TK2MSFTNGP11.phx.gbl...
Don't create your own thread, use the CLR threadpool via the
System.Threading.Timer class. This will fire a method at a timed interval on a
threadpool thread and this method can check the XML file.

However, be careful in that you sound as if you then want to update the user
interface when the XML file has changed. You will need to call
Control.BeginInvoke on one of the controls on the form (the datagrid itself
would work well) and pass it a method you want executed on the UI thread that
will perform the datagrid refresh. This is because only the UI thread is
allowed to update the UI in any way.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

Hello:
I have 2 windows application 1st one is periodically writing specific data
to XML file , the 2nd application has a dialog with DataGrid , the datagrid
filled with information in the XML generated by 1st application and should
be updated as soon as the XML file is update, so I decide to code a
continously running thread that checks the XML every specific time and
refresh the contents of datagrid
the question :
1. How can I code a thread that continously checks the XML after specific
time.

Best Regards

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andrea | last post by:
Hello, I am looking for the directions on how to set a report to print continuously, without a paper feed. I have set one up using the Label Wizard, but how do I set it up in an existing report? ...
6
by: lauren quantrell | last post by:
I am using a timer to display the time it takes a user to complete a file transfer using the code below. The code below will display the total elapsed time, but is there a way to update the time...
1
by: Dan | last post by:
Good Day, I have a Windows Service that is responsible for processing somes files. One method of the service invokes another method which may take a while to complete its work. Something like...
0
by: nandha | last post by:
H I have a doubt in VC++ regarding file reading and displaying in the GUI (Dialog I have a binary file, which contains several piece of information , i have to read the information continuously...
9
by: mareal | last post by:
I have noticed how the thread I created just stops running. I have added several exceptions to the thread System.Threading.SynchronizationLockException System.Threading.ThreadAbortException...
2
by: Colli | last post by:
Hi: I need to setup a continuously updating system Date/Time in my user interface. I can get the system date/time and can cause it to update with a button-click but I can't seem to figure out how...
9
by: esakal | last post by:
Hello, I'm programming an application based on CAB infrastructure in the client side (c# .net 2005) Since my application must be sequencally, i wrote all the code in the UI thread. my...
2
by: =?Utf-8?B?QWxwaGFwYWdl?= | last post by:
Hello, I have a class MyWorker. Each time I create a new instance of MyWorker, I queue it to the ThreadPool. So, 1 MyWorker object is pooled and belongs to its thread (there can't have 2...
3
by: bgold12 | last post by:
I'm curious about how websites deal with the problem of continuously growing data. For example, there are many forums that preserve all posts for many years back, and are continuously receiving and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.