Timeouts

  • Thread starter Thread starter Nikolay Petrov
  • Start date Start date
N

Nikolay Petrov

Let's say I have a method that do something, doesn't matter. Some times it
happens that this method can't finish it's job.

How to implement a kind of Timeout in the calling method, so it doesn't wait
for the called method to finish, but instead generate an error to do
something else, and eventually stop the not responding method?

I was thinking about using threads.

Just wonder isn't there a more appropriate method.

Thanks in advance
 
You can use a Delegate pointing to your method. Use Delegate.BeginInvoke
and store the IAsyncResult object it returns. Then you can use the
IAsyncResult.AsyncWaitHandle.WaitOne method to implement the timeout.

--Robby
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top