this way or that way?

I've got some code that basically goes through some handles until it finds the 'window' I'm looking for...it then does it's thing and everything is great...however...just before it 'does it's thing' - there's a pop up window that I'll be working toward eliminating...

Here's my question:

> Is it a big deal if this code is 'continually' cycling through the open handles on my system - is that going to drag my utilization way down?  Right now, it runs about every 10 hours until it finds the window, then 'rests' until the next go around...
LVL 67
sirbountyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics TeacherCommented:
As long as you are you using either a Timer with a reasonable interval or a Thread with a reasonalbe call to System.Threading.Thread.Sleep() you should be okay...
sirbountyAuthor Commented:
I'm not...(yet)...

As of right now, I'm using something along the lines of
if window found
 shell...myprogram...
 sleep 10 hours
else
 sleep 5 seconds
end if

Problem I'm having is that it's not 'always' 10 hours...it could possibly occur more frequently (much more, I'm afraid) than that...so I'm curious if I had some sort of full-time monitor set up if it would crush my system?
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics TeacherCommented:
If you polled in a While...Wend loop WITHOUT a call to Sleep() then Yes, it would drag down your CPU.

You can put your code that checks for the window in a Timer event and check every 5 seconds and that would be no big deal in my opinion.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sirbountyAuthor Commented:
So you're saying I should be okay if I do the following...

In Form_load call my app-finder routine (in my module)
and from there have a timer that will run through all handles looking for a match every 5 seconds

...or...
a while...
loop through handles
sleep 5 seconds
wend

I wonder if there's any difference...?  Hmm...I may have to test it...

Basically, I'm checking to ensure my vpn connection stays active.  Once it drops, I want it to auto-reconnect...it's working when it simply goes to the maximum 10-hour threshold, but occasionally it'll drop for whatever other reason and my app's not working correctly then... : \
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.