Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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....

"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Posted

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 :)

Posted
I don't suppose you could change the server program to simply send you an alert when something happens....
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Posted

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

Posted

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....

"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Posted

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 :)

  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...