Marc

Marc

  • NA
  • 205
  • 53.8k

Convert AutoResetEvent to TimerCallBack

Jan 28 2015 8:37 AM

This is some code I grabbed off of the Internet that I've modified a little thus far, but what I am having issues with is setting the statusIs to the TimerCallback. I don't know if thats because of my CheckStatus module or what.  I haven't modified the CheckStatus module much from where it was, just the type returned and the return of course. Needless to say TimerCallback can not convert statusIs(AutoRestEvent type).

 

AutoResetEvent autoEvent = new AutoResetEvent(false);

var statusChecker = StatChecker(10);

var statusIs = CheckStatus(statusChecker);

TimerCallback tcb = Convert.ChangeType(statusIs, TimerCallback, GetFormat); // here is the issue or could be

Timer stateTimer = new Timer(tcb, autoEvent, 1000, 250);

autoEvent.WaitOne(5000,false);

stateTimer.Change(0, 500);autoEvent.WaitOne(5000,

 

false);

stateTimer.Dispose();
 
 
Here is the other modules:

 

public int StatChecker(int count)

{

invokeCount = 0;

maxCount = count;return count;

}public AutoResetEvent CheckStatus(Object stateInfo)

{AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;

 

Console.WriteLine("\n" + DateTime.Now.ToString("h:mm:ss.fff") + " - Checking status: " + (++invokeCount).ToString() + "/n");

 

if(invokeCount == maxCount)

{

 

// Reset the counter and signal Main.

invokeCount = 0;

autoEvent.Set();

}

 

return autoEvent;

}