473,480 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Streaming without CPU occupying?

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?

Dec 17 '05 #1
0 907

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5434
by: Markus Ernst | last post by:
Hi I know this question is rather HTTP related than PHP, but I did not find an HTTP group on my news server. I deliver some files with the following PHP syntax: header('Content-Description:...
4
2087
by: Poldanziern | last post by:
Is there such a thing in C++ as stream which you can pass data into and then retrieve data out of on the other end (without interacting with the user or a file)? For example, I'd like to extract...
2
339
by: Antonio | last post by:
Good Morning, in my personal site http://www.etantonio.it/en I've a section talking about diving where I would want to insert a video of an immersion in Sharm El Sheikh, it is in DVD format and I...
2
9730
by: mpaliath | last post by:
Hi guys I am currently involved in a project which requires me to recieve and play streaming video as well as send it. In Visual C++ is there any free library which helps me do this as...
2
8416
by: SPG | last post by:
Hi, Two questions for you all.. Firstly, is there a way of streaming video using PHP? At the moment I just have a link to a video file and the whole thing downloads before playing which is a...
1
1130
by: fiem | last post by:
hi, I want to know is class is occupying any Memory?? suppose if i declare 10 different classes and don't create any instance of that classes, is that classes occupying any Memory?? class var...
2
2404
by: donnyf | last post by:
Hi guys. I've put together a website ( http://worldwidemediaproject.com ) that is a database of internet streaming tv/radio stations from around the world. I have built the site with all users in...
2
1714
by: Bubbs | last post by:
hi, Lemme give u a little background on my problem. Ive created a client and server applications that receive and stream live time values. The client software is a clock that receives the time and...
1
2831
by: Faisal Shafiq | last post by:
I want to upload a file direct to the Silverlight Streaming Service from a Web Client such as silverlight application. As per our product requirement we want to upload a .WMV file directly from...
0
7048
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7050
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6743
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6966
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4787
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
564
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.