Possible Duplicate:
Set timeout to an operation
How can i set timeout for a line of code in c#.
For example
RunThisLine(SomeMethod(Some Input), TimeSpan.FromSeconds(10))
run SomeMethod
with 10 second time out.
Thanks in advance.
Possible Duplicate:
Set timeout to an operation
How can i set timeout for a line of code in c#.
For example
RunThisLine(SomeMethod(Some Input), TimeSpan.FromSeconds(10))
run SomeMethod
with 10 second time out.
Thanks in advance.
You can use the IAsyncResult and Action class/interface to achieve this.
You can use the Task Parallel Library. To be more exact, you can use
Task.Wait(TimeSpan)
:I use something like this (you should add code to deal with the various fails):