嗨,我正在尝试使用EventWaitHandle类创建调度的实现
以以下示例为例:
// 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;
}
阅读代码中的TODO
简单地说:所以我希望能够调度一个超过int.MaxValue的执行,并手动强制跨流程执行
也许是实现完全相同场景的更简单方法?