|
-
thread: heartbeat and reset
I am nwe to C# thread. I have a heartbeat class which will run in a thread
like this:
Class Heartbeat
{
private int miRate;
private int miCount = 0;
public Heartbeat(int Rate) { this.miRate = Rate; }
public void Start() {
while ( true )
{
Thread.Sleep( 1 ) // sleep 1 second
if ( this.miCount++ >= this.miRate )
Console.WriteLine("Heartbeat {0}", DateTime.Now);
else
this.miCount = 0;
}
}
public void Reset()
{
this.miCount = 0;
}
}
After I create a Heartbeat obj and start it in a thread, I do need to call
Reset sometimes to reset the heartbeat. However, it does not run correctly.
What happens if the thread is in sleep mode while calling its Reset mothod?
Is Reset still accessible? How can I reset the heartbeat correctly?
D. Chu
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks