Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With the apparent lack of built-in support for IHttpAsyncHandler timeouts, presumably you must manage your own timeout. Perhaps this is by design; after all you are choosing an asynchronous pattern - who does MSFT think they are trying to set a default timeout for your long running task?</p> <p>What I would do is use <a href="http://msdn.microsoft.com/en-us/library/system.threading.threadpool.registerwaitforsingleobject.aspx" rel="nofollow">ThreadPool.RegisterWaitForSingleObject</a> to manage your polling with an appropriate timeout. Here is a code sample I use to avoid waiting on a web service that never returns:</p> <pre><code>private const int REQUEST_TIMEOUT = 30000; // miliseconds (30 sec) private void CallService() { try { string url = "somewebservice.com"; WebRequest request = WebRequest.Create(url); // Asynchronously fire off the request IAsyncResult result = request.BeginGetResponse(new AsyncCallback(MyRoutineThatUsesTheResults), request); // Handle timed-out requests ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, new WaitOrTimerCallback(RequestTimeout), request, REQUEST_TIMEOUT, true); } catch (Exception ex) { _logger.Error("Error during web service request.", ex); } private void RequestTimeout(object state, bool timedOut) { if (timedOut) { WebRequest request = (WebRequest)state; _logger.WarnFormat("Request to {0} timed out (&gt; {1} sec)", request.RequestUri.ToString(), REQUEST_TIMEOUT / 1000); request.Abort(); } } </code></pre> <p>You will need an IAsyncResult to work with this approach but that's an established pattern you shouldn't have trouble running down samples about.</p> <p>Also, you will run into issues when IIS decides to recycle your app pool / tear down your app domain while your polling is still running. If that's a condition you want to handle, you can use <a href="http://haacked.com/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx" rel="nofollow">HostingEnvironment.RegisterObject</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload