473,396 Members | 1,872 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,396 software developers and data experts.

one back ground thread processing!

I have a process that I am writing, which receives the requests through
filewatcher. Once I get the request, I need to start a thread asyn. I
shouldn't start the thread again until the running thread is completed
even if there are more requests pending. Here is how I precive it and
please correct me if I am wrong or going to be bad on performance.

1. On file add/delete on the file watcher, I run a method called
processrequests.
2. In this I will check and see if any requests pending.
3. If any requests pending,
3.1 I will check and see if the thread is running (I still don't know
how to do this)
3.2 If the thread is not running start the thread to process the
request.
3.3 if the thread is already running get out of the method. Since the
request will be processed when the step 4 completes.

4. When thread completes the request, it removes the requested file
thus calling processrequests and I go into loop here.

My questions are
1. How can I create only one thread that is visible to processrequest
method.
2. How can I make sure if that thread is running (I remember looking at
the state of the thread but I heard some issues with it, even though
the thread is running, it come back with the status of completed, I may
be wrong)

Thanks.

Sep 5 '06 #1
1 1773

DBC User wrote:
I have a process that I am writing, which receives the requests through
filewatcher. Once I get the request, I need to start a thread asyn. I
shouldn't start the thread again until the running thread is completed
even if there are more requests pending. Here is how I precive it and
please correct me if I am wrong or going to be bad on performance.

1. On file add/delete on the file watcher, I run a method called
processrequests.
2. In this I will check and see if any requests pending.
3. If any requests pending,
3.1 I will check and see if the thread is running (I still don't know
how to do this)
3.2 If the thread is not running start the thread to process the
request.
3.3 if the thread is already running get out of the method. Since the
request will be processed when the step 4 completes.

4. When thread completes the request, it removes the requested file
thus calling processrequests and I go into loop here.

My questions are
1. How can I create only one thread that is visible to processrequest
method.
2. How can I make sure if that thread is running (I remember looking at
the state of the thread but I heard some issues with it, even though
the thread is running, it come back with the status of completed, I may
be wrong)
What you want, it seems is a background worker thread that consumes
requests off a queue, and a foreground thread that waits for an
external stimulus (file watcher) and in response to that queues
requests to be processed.

You might want to take a look at Jon Skeet's article on
multi-threading. In that article he gives precisely this example.

http://www.yoda.arachsys.com/csharp/threads/

Sep 5 '06 #2

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

Similar topics

14
by: Jim Hubbard | last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
14
by: Michael C | last post by:
Hi all, I'm now trying to update a status indicator via a Timer control on a worker thread. The status indicator is just a label on the main form, but I'm having trouble figuring out exactly...
2
by: BG | last post by:
We're having trouble writing the code to update a UI control (label.Text) from a secondary thread. We're using C# with Windows Forms. We have a main form named MainForm, a splash screen form...
3
by: Stephen Miller | last post by:
I have an ASP.Net application that sends a NetworkStream to a .Net Service, which has a TcpListener listening on a port for the ASP.Net client. When it receives a request it creates a new thread...
0
by: Johanna | last post by:
Hello, Thread was being aborted exception is thrown by my asp.net application. I hope someone could help me with this error that I get in windows 2003 server. This error has not occured with...
5
by: taylorjonl | last post by:
I am completely baffled. I am writting a daemon application for my work to save me some time. The application works fine at my home but won't work right here at work. Basically I have a...
5
by: Soren S. Jorgensen | last post by:
Hi, In my app I've got a worker thread (background) doing some calculations based upon user input. A new worker thread might be invoked before the previous worker thread has ended, and I wan't...
12
by: Andrew Bullock | last post by:
Hi, I'm using a second thread within my program to do some long calculations, without locking up the UI: worker = new Thread(new ThreadStart(myClass.Run)); worker.Start(); I want to be...
176
by: . | last post by:
9/11 Mysteries http://video.google.com/videoplay?docid=-8172271955308136871 http://www.911weknow.com Ignore those who would go to great effort and expend much of heir time in poo-pooing this...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
0
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,...

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.