473,770 Members | 3,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7782
Don't create your own thread, use the CLR threadpool via the System.Threadin g.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.BeginIn voke 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(Thr ead_ContinuousC hecker));
thread.IsBackgr ound = true;
thread.Name = "Data Polling Thread"; // <-- Useful for debugging, way more than
a worker pool thread.
thread.Start();

private void Thread_Continuo usChecker() {
while(true) {
// Do your checking
if ( newData ) { Process(); BeginInvoke(Upd ateGUI); }
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******@devel op.com> wrote in message
news:e8******** *****@TK2MSFTNG P11.phx.gbl...
Don't create your own thread, use the CLR threadpool via the
System.Threadin g.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.BeginIn voke 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
3096
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? I have looked through all the property settings and cannot find any reference to it. It is driving me mental! Thanks, Andrea
6
4499
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 continuously as the file is being downloaded? Help is greatly appreciated, lq Public sngStart as Single Public sngEnd as Single Public sngElapsed as Single
1
2319
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 this pulbic class A { public void ProcessFile()
0
355
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 from the file and continue to display the information in the GUI, i have created a GUI , using dialog based and having a list box in that dialog, After reading a part of information i have to display in GUI, and again i have to keep on reading ...
9
3078
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 System.Threading.ThreadInterruptedException System.Threading.ThreadStateException to see if I could get more information about why the thread stops running but that code is never executed. Any ideas on how I can debug this?
2
1965
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 to cause it to update continuously (as it does in the bottom right corner of my desktop). Can anyone help me with this. Please E-Mail me directly with your advsce. Thanks. Colli From...
9
3270
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 problem occurs when i try to show a progress bar. The screen freezes. I know i'm not the first one to ask about it. but i'm looking
2
1634
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 MyWorker in 1 thread from the ThreadPool). When MyWorker is initialized or instanciate, I use an asynchronous delegate to execute a long running process (depending on users, the job can be quicker). So, this async delegate will use or create a new...
3
1825
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 storing new posts all the time. No website has access to an infinite amount of storage space, so: What kind of buffer (i.e. space available) do they like to have, or in other words, how much time do they have before they would run out of...
0
10228
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10057
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10002
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9869
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.