Hi im trying to create an implementation of scheduling using the EventWaitHandle class
Take the following example:
// Program 1
static void Main(string[] args)
{
EventWaitHandle wh = new EventWaitHandle(false,EventResetMode.ManualReset,"MyCrossProcessEventHandle");
wh.Set();
}
// Program 2
static void Main(string[] args)
{
EventWaitHandle wh = new EventWaitHandle(false, EventResetMode.ManualReset, "MyCrossProcessEventHandle");
while (true)
{
var span = CalculateSpan();
wh.WaitOne(span);
// TODO Implement check, why did execution proceed?
// timeout ocurred
// OR
// Eventhandle was set
//
// if timeout occured
// break the current iteration loop (And thereby calculate a new timeout)
//
// if event.set
// continue execution
// SNIP SNIP - More code here
}
}
private static int CalculateSpan()
{
DateTime datetoRun = new DateTime(2020,01,01,00,00,00);
var span = datetoRun - DateTime.Now;
if (span.TotalMilliseconds >= int.MaxValue)
{
return int.MaxValue;
}
return (int)span.TotalMilliseconds;
}
READ THE TODO IN THE CODE
Boiled down: So i want to be able to schedule an execution for more than int.MaxValue, and manually force execution cross process
Perhaps an easier way of achieving the exact same scenario?