Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Streaming without CPU occupying?

Reply
Thread Tools

Streaming without CPU occupying?

 
 
=?Utf-8?B?dGhlIGZyaWVuZGx5IGRpc3BsYXkgbmFtZQ==?=
Guest
Posts: n/a
 
      12-17-2005
Following problem:

I want to stream a file to the client, but the logic takes too much CPU time
(100% in fact..) this is the code:



public class Download : System.Web.UI.Page

{

private byte[] buffer;
private AsyncCallback callback;
private Filestream fs;



private void Page_Load (object sender, System.Eventargs e)

{

fs = File.Open (....) // I won't bore you with the non interesting parts

Response.Clear();

Response.ClearContent();

Response.ClearHeaders();

Response.AddHeader("content-disposition", "attachment;
filename=blabla.exe");

Response.ContentType = "application/octet-stream";

fs.BeginRead(buffer, 0, 1024, callback, null);



}



void whencomplete (IAsyncResult Result)

{

int BytesRead = fs.EndRead(Result);

if (BytesRead > 0)
{

Response.BinaryWrite(buffer);

Response.Flush();

fs.BeginRead(buffer, 0, 1024, callback, null);

}

if (BytesRead == 0)
{

fs.Close();

Response.Close();

}



in private void InitializeComponent():

{

buffer = new byte[1024];

callback = new AsyncCallback (whencomplete);

}





---

This works, but it does take the whole CPU. If I add a sleep cycle in
whencomplete:

---


if (BytesRead > 0)
{

Response.BinaryWrite(buffer);

Response.Flush();
Thread.Sleep(100);

fs.BeginRead(buffer, 0, 1024, callback, null);

}
----

The CPU Utilization goes nearly to zero, but only with one running download.
I tried 3 downloads at the same time, and the CPU was again quite occupied.

What's the more effective way to stream? Is it even possible to stream,
without a high cpu utilization, since it's basicaly a .aspx site, which is
running in a loop?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How , system cpu and user cpu times calculates pavunkumar C Programming 1 02-27-2009 08:29 AM
streaming mp3 files without allowing download Sunfire ASP .Net 7 11-10-2007 07:10 PM
HELP! Trying to understand the logic behind CPU core speeds and whole CPU speed. dimon Computer Support 4 11-10-2006 04:01 PM
Pentium CPU vs Intel Celeron CPU and the Wireless Mouse kirk lives! Computer Support 4 05-02-2004 06:59 PM



Advertisments