Is there a way to Interupt a sleeping thread? If I have code similar to this.
while(true){
if(DateTime.Now.Subtract(_lastExecuteTime).TotalHours > 1)
why not use a BlockingCollection? I see it as a much more elegant approach than the accepted answer. i also do not think there is much overhead compared to the monitor.
here is how to do it:
initialize a BlockingCollection as a member:
BlockingCollection<int> _sleeper = new BlockingCollection<int>();
insted of
Thread.Sleep(10000)
do this
int dummy;
_sleeper.TryTake(out dummy, 10000);
to wake it up you can use this code
_sleeper.Add(0);