|
What's the best way to throttle the download speed on an httpwebrequest? It looks like it creates a seperate thread and does internal buffering on the download but I would like to have a max bandwidth limit imposed.
|
|
|
|
|
In a multitasking environment, it's not easy to create a perfect throttling system, but a simple one can be:
In a separate thread (because you don't want your program to "hang" waiting the download), after each "Read" call you do on the response stream, check the # of bytes received in the last second, let's call it nRead. If Speed >= nRead, sleep the rest of the second. If there's more to read, read min(Speed-nRead, you buffer size) bytes.
It's a bit confuse, but I think I made it clear...
lazy isn't my middle name.. its my first.. people just keep calling me Mel cause that's what they put on my drivers license. - Mel Feik
|
|
|
|
|
An Http Web Request/Response is internally managed by a System.Net.ServicePoint moniker which hides the underlying connection. This connection is buffered (hardcoded there, it's always 4KB), and there is no way to do direct throughput, which is probably why you see it slower than a standard WIN32 Wininet connection for instance.
The System.Net.Connection and System.Net.ConnectStream classes are not documented. That's however there where paquets are processed.
In addition, you cannot configure the underlying connections at the HttpWebRequest/HttpWebResponse API level.
Back to real work : D-26.
|
|
|
|
|
Good to know. Thanks for the prompt response. Is it possible however to use the Sockets classes to do software bandwidth restrictions?
|
|
|
|
|
The Socket class from .NET is a thin wrapper around Winsocks2. So that's plain hardcore TCPIP to fork with. At a point where even one could question the usefulness of doing socket programming with C#.
Back to real work : D-26.
|
|
|
|
|
I guess the main problem is that the webrequest/response method seems to hog all available bandwidth. Unlike when you open up several IE browsers at once on a slow link. They seem to be scheduled better.
But if I have downloads running from a webresponse, I'm not able to use IE at all with a dialup connection. All dns requests time out.
|
|
|
|
|
Hi there !
I want to embed the MS IE Control into my application ( as covered by some tutorials here )
However ih ave one special requirement.
Is it possible to get a BITMAP ( System.Drawing.Bitmap )
from this control ? I need that because i want to store it in a Texture for Managed DX9 .... any clues on this one ?
Of course it would also be great to do that even if the webbrowser was not visible on screen..
In C++ i did that already ( overridng WM_PRINT etc and copying the image data by hand )
But how to do this in C#/NET
Thanks
|
|
|
|
|
If you've already done it in C++, the most efficient use of your time may be to wrap that code in a managed C++ object and then use that object from C#.
John
|
|
|
|
|
Hi!
I use Visual Studio .NET and am looking for the most versatile video control in Visual Studio .NET. Ideally,it would play windows media, allow full screen, render invisible its controlbar if need be, allow programmatical positionning of the video to play it at themoment of the video we wish to view.
I program in C# and this is my first real project at my new job,
so any help would be really appreciated...
Thanks!
Orlanda
Coding is a family business
|
|
|
|
|
If that was for playback versatility, I would have suggested DirectShow[^], but as far as I know there is no DirectShow ocx to play with. You'll have to import the quartz type-library, and debunk the right interfaces.
Of course one would suggest the Windows Media player SDK. Unless you are an anti-MS person, you have the Windows Media player ocx already to play with. You should build great apps, but there is one problem : depending on the ocx or type-library you import, you are going to force end users to have the same WindowsMedia run-time version just to playback the videos. And this can be cumbersome since MS is pushing only the latest Windows Media run-times, which are supported by XP.
Back to real work : D-27.
|
|
|
|
|
.S.Rod. wrote:
And this can be cumbersome since MS is pushing only the latest Windows Media run-times, which are supported by XP.
Didn't MS stop distributing WMP as a control after 6.4? (FWIW, 6.4 ships with all the latest versions of WMP, %PROGRAM FILES%\Windows Media Player\mplayer2.exe)
Maybe its the sleep deprivation doing the thinking for me (it certainly doesn't feel like its 3pm :p)
James
Sig code stolen from David Wulff
|
|
|
|
|
<winsysdir>\msdxm.ocx (the only static dependency is quartz.dll (DirectShow actually).
I have the 6.4 version because indeed I've never upgraded WindowsMedia (for god sake, I don't want a play behave like a turtle!).
I don't know about other releases. An educated developer would check out the public MS NGs for this topic.
Now I remember the NDA MS sent me a couple of years ago when I wanted to distribute a windows-media based app. Scaring, those 40 printed pages looked like my testament.
Back to real work : D-27.
|
|
|
|
|
I can not seem to get a record/row to delete from my XML file, my code for removing is this.
<br />
private void button5_Click(object sender, System.EventArgs e)<br />
{<br />
try<br />
{<br />
row = lstAccounts.SelectedIndex;<br />
<br />
lstAccounts.Items.RemoveAt(lstAccounts.SelectedIndex);<br />
<br />
ds.Tables[0].Rows[row].Delete(); <br />
ds.GetChanges();<br />
ds.Tables[0].Rows[row].AcceptChanges();<br />
<br />
}<br />
<br />
catch (Exception p)<br />
{<br />
MessageBox.Show(p.Message);<br />
}<br />
}<br />
I am trying to remove this code from a Complex type XML file. for some reason the brackets are removed from the code =\
<br />
<Account><br />
<UserName>Please enter your name.</UserName><br />
<UserEmail>Please enter your E-mail.</UserEmail><br />
<LogonName>Please enter your E-mail Account name.</LogonName><br />
<Password>Please enter your E-mail Password</Password><br />
<AccountName>New Account...</AccountName><br />
<Incomming>Please enter your POP3 server address.</Incomming><br />
<Outgoing>Please Enter your STMP server address.</Outgoing><br />
<IncommingPort>110</IncommingPort><br />
</Account>
Sometimes i get the error, there is no row at position 0 and sometimes i do not get it. Any help would be nice, ive spent a while reading some books and the msdn but i cannot figure out what i am doing wrong.
thanks
xarx
|
|
|
|
|
I don't know what's causing your problem. However, you might get the piece of informtion you need by changing "p.Message" to "p.ToString()". When dealing with Exceptions, the ToString() method gives much more information than the Message property.
John
|
|
|
|
|
Mr Clifton told me what i was doing wrong, I was not writing the deleted row back to the xml file. Now everything is fine. Thank you for replying =)
|
|
|
|
|
Do C# database classes have anything like the old ADO had:
while(!pDs->EOF())
{
/////
pDs->MoveNext();
}
I have noticed that we have tables, rows, andcolumns, but i am
curious as to how maintain a dataset between pages in a case
such as a multipage search engine?
|
|
|
|
|
If you use a SqlDataReader , this may help:
SqlDataReader r = cmd.ExecuteReader();
while(r.Read())
{
}
As far as part 2, you could use a page Cache of the dataset, and a Repeater control you modify to do the "pagination" The Microsoft .NET Pet Shop 2.0[^] has an example of one of those to paginate data.
-- ian
|
|
|
|
|
You could also do that with OleDbConnection like this:
OleDbDataReader myReader = myCom.ExecuteReader();
while(myReader.Read()){
// do your thing here with myReader
}
Børge Warvik
|
|
|
|
|
please see this code i want to start a process.After successful
starting i want to get its id for further processing.For that
purpose most of my processes are setup files (of some software like installers)
most of the processes execute this code successfuly but when i start
a process for example setup file of yahoo messanger installer or VCD Cutter installer
and some other software they all raise an exception(InvalidOperationException)
at last line although the process started successfully and its window appears
,and started process has its existance.
i want to get its id only(in last line of this code ).
my question is
why it raise an exception although started process has its existance?
i think its id is changed.am i right ?
if yes how to trace it id?
or it might be possible that the main process i start also start some other process and
exit itself. if thats true how to trace these processes?
int idpro;
tmpProcess = new Process();
tmpProcess.Exited += new EventHandler(this.ProcessExited);
tmpProcess.EnableRaisingEvents=true;
tmpProcess.StartInfo.FileName=strProcName;
try
{
tmpProcess.Start();
while(! tmpProcess.Responding)System.Windows.Forms.Application.DoEvents();
}
catch
{
}
idpro=tmpProcess.Id;
r00d0034@yahoo.com
|
|
|
|
|
Your process needs to have a main window handle for .Responding to work well. (.Responding will send it a timeout message and expects an answer).
I guess you may avoid any exception raise if you would do that instead :
if (tmpProcess!=null && tmpProcess.MainWindowHandle!=IntPtr.Zero) idpro = tmpProcess.Id;
PS : .Responding does not work on W9X systems under certain circumstances, as said in the doc.
Back to real work : D-27.
|
|
|
|
|
first of let me tell you i am using xp.
GOOD CHECK but that check avoid me to get id of an existing window like yahoo messanger because its window exist after calling start but its id dont.
is it possible that tmpProcess is not null and its id also dont exist.
please tell a little bit about this check
tmpProcess.MainWindowHandle!=IntPtr.Zero
what that IntPtr.Zero is?
r00d0034@yahoo.com
|
|
|
|
|
imran_rafique wrote:
GOOD CHECK but that check avoid me to get id of an existing window like yahoo messanger because its window exist after calling start but its id dont.
is it possible that tmpProcess is not null and its id also dont exist.
I don't like the way the .NET Process class gets a process ID, it assumes several things internally, and depending on the process, they may well be wrong.
I would definitely use interop to get that process ID, it should not be that hard.
imran_rafique wrote:
tmpProcess.MainWindowHandle!=IntPtr.Zero
that's aimed to check if the mainwindowhandle is not null. IntPtr has an enum inside, IntPtr.Zero is one of the values of that enum.
Back to real work : D-27.
|
|
|
|
|
whats interop?
r00d0034@yahoo.com
|
|
|
|
|
[DllImport("kernel32", CharSet=CharSet.Auto)]
static public extern int GetCurrentProcessId();
Back to real work : D-26.
|
|
|
|
|
Hi, I am playing with the HttpRequest class to try to make something work. I found that it appears, everytime you user the GetResponse() from the WebRequest, you have to initialize the object again, to get proper response in the pages that are authenticated. Is this normal, should it be like this?
WebRequest request = (HttpWebRequest) WebRequest.Create(URI);
/... do the network credentials here
request.GetResponse();
/... do something else
//this line has to be here to use GetResponse() again.
request = (HttpWebRequest) WebRequest.Create(URI);
/....
request.GetResponse();
K.D.
|
|
|
|