How can i have any kind of data returned from a method or property within a time frame, and if any data is returned within that time frame an exception is thrown?
Pretty much I have a simple method that will perform a simple task, once performed the method returns a value, and if any value is returned within 100 milliseconds I want that the method be aborted and an exception be thrown, for instance a TimeoutException for example, any kind of exception, as long it does the task.
If you are on .NET 3.5 and can’t use Parallel Extensions, you can use asynchronous delegates. This has the added benefit of rethrowing exceptions thrown by the method on the calling thread. The timeout logic in this example relies on a WaitHandle, as mentioned by leppie.