473,420 Members | 4,460 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,420 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 7744
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.