Method timeout

  • Thread starter Thread starter Nicholas Paldino [.NET/C# MVP]
  • Start date Start date
N

Nicholas Paldino [.NET/C# MVP]

The best way to do this would be to spawn another thread in your method,
and then wait on the execution thread until the task is complete. If the
method has not completed, then you would then fire your event indicating
that the method timed out.

Hope this helps.
 
Hi...

One mechansim to achive this affect would be to call the method thru a
delegate async. You can set a timeout period at the call site. The only
downside is that you would need to make sure to use this delegate for all
calls into the method.

If you need to do it in the method itself, you can
1. Create a worker thread that uses an event
2. Use context interception and have the interceptor do the timeout
monitoring

John
 
Hello.
How can I set timeout period for my method?
For example:
// ----------------------------------------------------
// NOTE: the function runs in separate thread
void MyFunction()
{
//
// do thomething ...
//
}
// ----------------------------------------------------
If the function don't end in 30 second, it must rise some event.
Can anybody tell me any optimal method how to do this?
 

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