VB app hangs up PC.

pts.
Tags:
Visual Basic
I have a VB6 application that is designed to check for the existance of a file every 30 minutes. This app is always (24x7) running on a specific computer and it uses the Sleep() function to activate the search for the file. There is no user interface or even an icon in the tray. The only way to tell if it is running is to use task manager (however, it always shows up as not responding). The problem is that at least once a week it hangs up the PC it is running on. Is there a better way to program something like this? Should it be running as a 'service'?

Answer Wiki

Thanks. We'll let you know when a new response is added.

I would just schedule it. The Windows scheduler is a lot more efficient than Sleep(). Just make sure you have an End in your code.

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • BeerMaker
    Running as a service is a good option. If you have access to VS .NET the project wizard will give you a nice templete to start from. Most of your VB6 code will convert to .NET. If that is to much work, you can make a VB6 ActiveX dll and execute classes in your VB6 dll from the .NET service. Anyway, if you have not used VB .NET, now is the perfect time to learn. Use the Event logs and more error trapping to determine why your VB6 program is locking up the machine. Probably you have an ON Error condition that is causing an infinite loop.
    0 pointsBadges:
    report
  • TimSeest
    The Windows scheduler is a good option but the scheduled tasks must be updated with new passwords as they are changed. For this reason, I use Launchpad as my scheduler. Launchpad is a $30 shareware scheduler. Sleep gives you a more accurate measure of time going by than a doevents loop but it still allows your app to hog the processor. I have found that using timer events to control looping on 24x7 apps allows them to share the processor dramatically better. If you want to know when your app is down, you could have it write a heartbeat record to a database every x minutes. A scheduled job on your database could then notify you if an expected heartbeat does not show up. I prefer using SQL jobs to VB for file monitoring and automated file management tasks. My SQL jobs move files between domains where the individual apps do not have the appropriate permissions; report when a network drive is low on disk space; and write the contents of working folders to a set of inventory tables. I do have a PC that runs five different 24x7 VB apps. The PC never ran more than a month without locking up. I got around this problem by scheduling an automatic reboot once a day.
    0 pointsBadges:
    report
  • Wmhammerly
    There are a number of gottchas in VB that can cause this. Some DLLs have memory leaks that after a week or so can exhibit the symptoms you describe. Also, a few code tips can clear this problem: 1. Make sure that anything you open (recordset, file, etc.) has a corresponding close in the proc that opens it if at all possible and make sure that it gets closed even if an error occurs elsewhere in the proc. 2. Set any object to Nothing when you are done with in (again, in the same proc if possible). For example: Set rs = New ADODB.Recordset ... do some stuff rs.close Set rs = Nothing Setting an object = Nothing clears up the stack and failing to do that can often cause a memory leak. 3. Heavy string manipulation in VB6 does not always trigger garbage collection. If you are doing a lot of string concatenation, such as sTemp = Left$(s1,5) & Mid$(s2,1,3) sTemp = sTemp & sOtherString You should clear sTemp when you are done with sTemp = "" Now I realize that this SHOULD NOT be necessary, but experience, and a few older white papers that escape my feeble memory suggests otherwise. By the way, on the same note, if you are doing string manipulation use Left$, Mid$, Right$, Trim$, etc using the $ function rather than Left, Mid, and Right. The ones with the $ are optimized for strings, have better gc and are lighter and faster. Hope this helps -- wayne
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following