您好我正在尝试使用 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;
}
阅读代码中的待办事项
归结为:所以我希望能够安排超过 int.MaxValue 的执行,并手动强制执行跨进程
也许是实现完全相同场景的更简单方法?