Tuesday, December 16, 2008

Add execution timeout for a block of code


delegate void EndProcessingWithTimeoutDelegate(ManualResetEvent m);

.....

bool TimedOut = true;
EndProcessingWithTimeoutDelegate d = delegate
{
ret = acctsAlloc.EndProcessing(MxEnumProcessAction.MxeProcessActionSave);
TimedOut = false;
m.Set();
};
d.BeginInvoke(m, null, null);
m.WaitOne(60000);
if (TimedOut) {
...
}
else
{
}

Note that Timeout in 60 seconds

No comments: