Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Threading and timer stop / start?

Status
Not open for further replies.

Raenius

Programmer
Oct 14, 2003
77
0
0
NL
Hi all,

I'm stuck with my application with regards to starting and stopping a timer based on whether a thread is finished or not.

In my main program there is a timer and when it is triggered it:

- stops the timer
- spawns a thread which goes about pinging IP addresses and updating a database

The problem is that when the PingThread finishes I want to start the timer again. Thats where the problem lies because I could not find the correct pace for that.

Is it viabale that I spawn a second thread which basically waits for the PingThread to finish and then call the timer.start() again from that thread OR would it be smarter to just start the timer again in the PingThread when it finishes...

Additional question, can I reach the timer.start() method from the original PingThread or not?

I'm getting really confused here...

Hope to get some fresh views on the subject.

Thanks!

- Raenius

"Free will...is an illusion"
 
When the PingThread finishes e.g. ThreadStart proc terminates rise an event and capture it in the main program and start again the timer.
Another solution is to use another timer which will watch the PingThread termination by querying the ThreadState of the PingThread object. If the ThreadState was Running and now is Stopped that means the PingThread finished and you can take create again the PingThread.
-obislavu-
 
If the main program would remain waiting until the thread finishes thus nullifying the idea of threading right?

If I were to implement a second timer which would check for the PingThread to be finished for like every 10 ms wouldn't that cause a performance problem?

The PingThread is handlike approximately 600 routers...

Is a listener thread unable to check if the PingThread is finished?

"Free will...is an illusion"
 
There will be no impact to the PingThread thread and you can use the Monitor class with Wait() /Pulse() methods to easy control the both threads for instance.
-obislavu-

 
Hi,

In regards to Obislavu's first answer:

"Another solution is to use another timer which will watch the PingThread termination by querying the ThreadState of the PingThread object. If the ThreadState was Running and now is Stopped that means the PingThread finished and you can take create again the PingThread."

I am trying to implement this now but I keep running into the following error:

[C# Error] MainScreen.cs(769): The type or namespace name 'PingThread' could not be found (are you missing a using directive or an assembly reference?)

Maybe its me programming over 8 hours straight but I can't seem to find out how to correctly read the state of the PingThread..

Can someone help me?

- Raenius

"Free will...is an illusion"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top