|
Hello all!
My block of code in question is this:
while (WB.IsBusy)
System.Threading.Thread.Sleep(1);
WB is a System.Windows.Forms.WebBrowser.
My concern is that the WB object was created by my class and is in the same thread, so by sleeping I wonder if it will stop the WebBrowser from processing whatever its busy doing. So if the while ends up getting run 100 times did I just Sleep for 100 extra, unnecessary, milliseconds?
My reason for using the Sleep is so the processor usage doesn't peg out while waiting for the WebBrowser.
I imagine that most of the IsBusy time is spent waiting for content to download and that while the thread is sleeping Windows will keep loading the data into the stream, but I'm guessing and I have no idea how to check.
So, am I way off base here? Is there a better way to wait for a WebBrowser object to finish what its doing?
Thanks all!
|
|
|
|
|
I would look for an event fired by the web browser, I am sure there's one for when a page finishes loading. Then you can just catch that event and start processing from there.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Indeed. Thank you for the response!
For the automation I'm making I need it to be able to handle a site that may stop responding =/
My full loop code is:
DateTime start = DateTime.Now;
DateTime stop = start.AddSeconds(_SecondsToWait);
while (!DoneLoading() && DateTime.Now < stop)
{
System.Windows.Forms.Application.DoEvents();
System.Threading.Thread.Sleep(1);
}
DoneLoading is a delegate that returns true once the page has sufficently loaded.
So, the reason I keep running the loop is that I need to check if the page is done loading or if _SecondsToWait has already passed. I don't want it to wait for an event that may never fire. If there is another way to do this, I'd love to learn about it!
|
|
|
|
|
Anticast wrote: or if _SecondsToWait has already passed
What about a timer then?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Anticast wrote: or the automation I'm making I need it to be able to handle a site that may stop responding =/
OK, so use a timer as well then, set to a nice long timeout, for pages that time out. This code is not what I was suggesting, it's still creating endless loops of wait events. Sleep(1) sleeps for a microsecond, 1/1000 of a second. This code will just call DoEvents with barely a pause.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Christian Graus wrote: Sleep(1) sleeps for a microsecond, 1/1000 of a second
1/1000 of a second is one millisecond. A microsecond is one millionth of a second I believe.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Oh, whatever. I doubt it would make much difference.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hi All;;;
I want To make textbox accept only character and not number,
(Active only character key ,backspace key, and apace key)
and disactive all other keys.
please help me,,,
thanks all
|
|
|
|
|
|
Try this code:
private void textBox1_KeyDown(object sender, KeyEventArgs e) {
if (e.KeyValue >= 48 && e.KeyValue <= 57)
e.SuppressKeyPress = true;
}
Regards,
Lev
|
|
|
|
|
I wrote this code it is close to what you are trying to do.
I am not a C# programmer however so here it is in VB.NET
''' <summary>
''' This routine will not let the user enter anything except numbers and dashes into the SSN textbox
''' </summary>
''' <param name="e">This is the Keypressevent from the calling form</param>
''' <remarks></remarks>
Public Sub sSocialKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
' allow backspace
If Asc(e.KeyChar) = 8 Then
Exit Sub
End If
'Dont catch control
If Char.IsControl(e.KeyChar) Then
Exit Sub
End If
'numbers Only
If Char.IsNumber(e.KeyChar) Then
e.Handled = False ' and cancel this keystroke
Else
e.Handled = True
End If
End Sub
Private Sub txtSocialSecurityNumber_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSocialSecurityNumber.KeyPress
sSocialKeyPress(e)
End Sub
Use the C# equivalent of this for the text box you are wanting to validate.
I hope this helps, BTW I know I am not the best programmer so please noone laugh very hard. LOL
Humble Programmer
|
|
|
|
|
I wrote an article[^] that does exactly the reverse - only numeric. It's not difficult to adapt it. There are a couple of comments at the bottom of the article on other approaches that you might find usefult too.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
string[] arFiles = Directory.GetFiles(System.Environment.GetFolderPath(System.Environment.SpecialFolder.InternetCache));
int x = 0;
foreach (string f in arFiles)
MessageBox.Show(arFiles[x]);
The above code will only get "desktop.ini", I'm not surprised though, I know this's a special folder but do you have an idea how to reach a specific file and read it's content in this folder??
Thank you guys!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Muammar© wrote: int x = 0;
foreach (string f in arFiles)
MessageBox.Show(arFiles[x]);
Huh? what is the purpose of f in the above snippet?
|
|
|
|
|
Okay okay I was so sleepy when I wrote this, I got it now, thanks Luc
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Muammar© wrote: foreach (string f in arFiles) MessageBox.Show(arFiles[x]);
What the ...??
How about looking at the file names and not the first element of an array over and over again.
foreach (string f in arFiles)
Debug.WriteLine(f);
|
|
|
|
|
Yes, I guess we shouldn't code after midnight. Thanks Dave!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Hi,
The files are located in several subdirectories and something like this will find them for you.
private void FindFiles() {
String[] files = Directory.GetFiles(
System.Environment.GetFolderPath(
System.Environment.SpecialFolder.InternetCache),
"*.*",
SearchOption.AllDirectories);
foreach (String file in files) {
Console.WriteLine(file);
}
}
Alan.
|
|
|
|
|
Thanks Alan, that does it!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Hi,
The wsdl web service is behind proxy. I can access the wsdl with the iexplorer but I cannot access the web service with C# client which works fine when the client is on the same machine as the service or the service is not behind proxi. I tried using wsdl utility with /proxy but it generated the same stub as without this option.
What do I do?
Thanks.
|
|
|
|
|
Hi All,
I have worked on Windows Apps before and deployed them easily because there were no local DB, however this time I need to deploy a Winform [C#] application along with the SQL Server DB which contains several tables and stored procs.
The query is
1) How to deal all deployment issues using Setup project only?
Regards
Grk
|
|
|
|
|
i have a wireless router and i want to restart it from my app. any idea ?
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Hmm, the only thing that comes to my mind... You definitely have a web-interface on the router, with a restart button, you can try to see what's the request it sends (sniff?) and send it yourself, you will need to authorize first, of course
Regards,
Lev
|
|
|
|
|
Hmmm, you were faster, dang...
|
|
|
|
|
But you beat me.
Simon
|
|
|
|