Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Rather than an ASP.NET page you should implement an <a href="http://msdn.microsoft.com/en-us/library/system.web.ihttpasynchandler" rel="nofollow">IHttpAsyncHandler</a>. ASP.NET page code puts many things between your code and the browser that would not be appropriate for transferring binary files. Also, since you're attempting to perform rate limitation, you should use asynchronous code to limit resource usage, which would be difficult in an ASP.NET page. Creating an <a href="http://msdn.microsoft.com/en-us/library/system.web.ihttpasynchandler" rel="nofollow">IHttpAsyncHandler</a> is fairly simple. Just trigger some asynchronous operations in the <a href="http://msdn.microsoft.com/en-us/library/system.web.ihttpasynchandler.beginprocessrequest" rel="nofollow">BeginProcessRequest</a> method, and don't forget to properly close the context to show you have reached the end of the file. IIS won't be able to close it for you here.</p> <p>The following is my really bad example of how to perform an an asynchronous operation consisting of a series of steps, counting from 0 to 10, each performed at a 500ms interval.</p> <pre><code>using System; using System.Threading; namespace ConsoleApplication1 { class Program { static void Main() { // Create IO instances EventWaitHandle WaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset); // We don't actually fire this event, just need a ref EventWaitHandle StopWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset); int Counter = 0; WaitOrTimerCallback AsyncIOMethod = (s, t) =&gt; { }; AsyncIOMethod = (s, t) =&gt; { // Handle IO step Counter++; Console.WriteLine(Counter); if (Counter &gt;= 10) // Counter has reaced 10 so we stop StopWaitHandle.Set(); else // Register the next step in the thread pool ThreadPool.RegisterWaitForSingleObject(WaitHandle, AsyncIOMethod, null, 500, true); }; // Do initial IO Console.WriteLine(Counter); // Register the first step in the thread pool ThreadPool.RegisterWaitForSingleObject(WaitHandle, AsyncIOMethod, null, 500, true); // We force the main thread to wait here so that the demo doesn't close instantly StopWaitHandle.WaitOne(); } } } </code></pre> <p>You'll also need to register your <a href="http://msdn.microsoft.com/en-us/library/system.web.ihttpasynchandler" rel="nofollow">IHttpAsyncHandler</a> implementation with IIS in whichever way is appropriate for your situation.</p>
    singulars
    1. This table or related slice is empty.
    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. 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.
 

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