I have an external dll with some methods I need to call. Also, I want to be able to configure a timeout for executing these methods, in order to abort them if execution time > config timeout. I call these methods on different tasks, like this:
Parallel.ForEach(....
{
Func<object> asyncFucntion = () => DynamicCall(method, paramList);
IAsyncResult ar = asyncFucntion.BeginInvoke(null, null);
if (ar.AsyncWaitHandle.WaitOne(timeout, true))
{
return asyncFucntion.EndInvoke(ar);
}
else
{
//HERE I NEED to stop DynamicCall. Timeout was EXCEEDED
}
});
Now, I have the possibility to get the DynamicCall Thread id and abort it. Is there any other way around? A more light way? I can't use the Cancellation Tokes, since i can't modify the external Dll
Thanks, Alex