dgburton Posted October 21, 2002 Posted October 21, 2002 Hi there! I have a VB.net app that starts a thread which constantly loops. The contents of the loop are as follows: 1. Uses the Internet Transfer Control's OpenURL method to open a URL from a server. 2. Checks whether the returned string (an html file) contains a certain sequence of charactors (this file contains data about the status of the server on which it is hosted) This all works fine and dandy but when I look in Task Manager the process is using nearly 100% of CPU time! - This is clearly unacceptable to me as the point of the program is to run in the background and alert the user when the status of the server (ie when the HTML file the OpenURL method retrieves, changes) Any ideas, or alternatives to the OpenURL method, would be most appretiated. Kind Regards, dan Quote
BillSoo Posted October 21, 2002 Posted October 21, 2002 I don't have vb.Net but..... If your program is running in the background, it probably SHOULD use up all the cpu processing time. After all, if cycles are available, it doesn't hurt to use them... If you try running a FOREGROUND app, like a spreadsheet, does your VB app cause any noticable delay? If not, it's probably not a problem. If you still have concerns about this, then you could use a timer instead of a loop.... Quote "I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
dgburton Posted October 21, 2002 Author Posted October 21, 2002 Thanks for the reply BillSoo :) When I mimize my app it slows everything else (including any other apps) down to a crawl, hence the problem :) :) I have tried a timer but I need the program to monitor the status of the file on the server at least once every second - it's actually a video server (with a camera attached) and the program in monitoring the input port that is activated when someone presses a button (doorbell) so the app functions like an intecom. Any further ideas would be most appretiated :) Quote
BillSoo Posted October 21, 2002 Posted October 21, 2002 I don't suppose you could change the server program to simply send you an alert when something happens.... Quote "I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
dgburton Posted October 21, 2002 Author Posted October 21, 2002 I can indeed get the server to do things when the input is triggered, these can be: 1. Run a PHP file on the video server itself (this could potentially send some alert to my VB.net app on the client PC) 2. Send an email. 3. Upload a file to an FTP server. But how would I get my VB app to 'pick up' on these events, preferably if I got the server to run a PHP script how could this communicate with the VB app? - (both server and client machine are on the same local network) many thanks :) dan Quote
BillSoo Posted October 21, 2002 Posted October 21, 2002 The PHP method sounds like it might be neatest and cleanest, however, I know nothing about PHP so I'd have to defer to somebody else. Using the old adage "When all you have is a hammer, the whole world looks like a nail".....we might use different tools to accomplish the same thing... For instance, you could have a VB program running on the video server that checks the html file. Since it is running on the server, it doesn't have to send large amounts of data over your connection. If it detects an event, it could communicate with your client using simple sockets protocol. As I said, this is kind of a kludge and it sounds like PHP might be nicer. I'll see if any of our PHP experts want to take a crack at this.... Quote "I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
*Gurus* Derek Stone Posted October 21, 2002 *Gurus* Posted October 21, 2002 Call the Sleep method of the Thread class (System.Threading) if you don't want the code to execute constantly. After all, that's what a loop does. Quote Posting Guidelines
dgburton Posted October 21, 2002 Author Posted October 21, 2002 thx for you reply :) I have experimented with tread.sleep() but I want the thread to check at least every second, so pausing for long periods is not acceptable :) Quote
*Gurus* Derek Stone Posted October 22, 2002 *Gurus* Posted October 22, 2002 Have it sleep for 500 milliseconds at a time. This will prevent the application from using "100%" of the processor. Quote Posting Guidelines
*Gurus* divil Posted October 22, 2002 *Gurus* Posted October 22, 2002 You really shouldn't be using the Internet Transfer Control under VB.NET. This control does not ship with the product. My suggestion would be to connect to the webserver on port 80, and issue a HEAD request rather than a GET. This will return just the HTTP headers to you and not the file itself, and one of the HTTP headers should be a last-modified date. If you're running a LAN, you should be able to do this every second or so quite safely. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
dgburton Posted October 22, 2002 Author Posted October 22, 2002 I tried using Thread.Sleep and that sorted out the cpu load problems :) - thx for the suggestion! I agree I shouldn't be using Inet in .NET, I've heard you can use the .NET WebClient ? Could anyone give me a little example of this, essentially this is what I'm doing using Inet... variable1 = Inet1.OpenURL("http://192.168.0.150/image.htm") If anyone could let me know how the same can be achieved in .NET without ising Inet I'd be most appretiative :) kind regards, dan Quote
*Gurus* Derek Stone Posted October 22, 2002 *Gurus* Posted October 22, 2002 Dim wcDownload As New System.Net.WebClient() Dim bDatabuffer As Byte() = wcDownload.DownloadData("http://192.168.0.150/image.htm") Dim sDatabuffer as String = Encoding.ASCII.GetString(bDatabuffer) Quote Posting Guidelines
dgburton Posted October 23, 2002 Author Posted October 23, 2002 thx for the code m8 :) will try it out now :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.