Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application Sleep code question 1

Status
Not open for further replies.

jtseltmann

Programmer
Jan 15, 2002
149
US
I have a simple little application that I am using to check a folder for files and if any are found, it moves them to another location. The program has been set up to stay running and use the Sleep API. There isn't much complexity to it and inside the Sleep loop there is a DoEvents. There is a basic form that shows the status but doesn't have many controls or anything either.

My questions...
1. When started the application shows MEM usage about 1500K then it jumps up to about 7000K after the first scan (every 15 minutes). If I maximize the form and then minimize it the MEM usage goes back down to 1000K and starts creeping up. Why does this happen like this? I'd just like to understand it better.

2. Its is possible that the MEM usage climbs up and causes a server error/reboot? I have tested and watched it scanning every minute and the MEM usage never goes over 10,000K but the server admins want to blame it for recent errors.

I have checked all the code and all variables are set = Nothing to clean up and delete. There are no complex loops other then through the dir to check for files. Anyone have any thoughts on where to check or common leak problems? I have never had a "running all the time app" so I was just looking for some direction.

Thanks all!
 
Update...
I forgot to mention that it is hard for me to replicate the test scenario but from what I can see there is no leak. The weird thing is that after its running for a while..the MEM usage goes up to about 7000-10000K BUT if I max and them min the app it goes back down to 1500K and starts over?

just looking for any help or thoughts.

Thanks!
 
The "usage" is the loop and DoEvents.

Try a Timer Object, or look up SetTimer and KillTimer APIs in the Keyword Search
 
It's worth pointing out that polling isn't necessarily the best way of seeing if new files have turned up in a folder ...
 
Thanks for the ideas. It seems this program runs a bit different on each server. I have been running it now in test mode and to really work it I have it scanning every 1 minute. It never goes above 3000K. This seems fine to me as the program has to eat some mem while its working...but does that seem odd or high?

I'll give the timer a try but this sleep seems to be working more consistenly while I'm testing.

What are the other possibley methods for checking for files? I'm open to suggestions...

thank you for taking the time!
 
You can always let the filing system tell you that a new file has arrived ... thread222-719707
 
strongm,

In the thread you referenced above, I was playing around with it and added a msgbox to the red section to know when the file was removed. However, when the file was added, both message boxes were displayed. I also removed the Cancelled=True becuase I would like this to run as long as the applicaiton is open.

Code:
        Select Case wombat.Action
            Case FILE_ACTION_ADDED
                If strFilename = strFileWatch Then
                    MsgBox strFilename & " added to monitored folder"
'                    Cancelled = True
                End If
            Case FILE_ACTION_MODIFIED
  [red]          Case FILE_ACTION_REMOVED
                If strFilename = strFileWatch Then
                    MsgBox strFilename & " removed from monitored folder"
'                    Cancelled = True
                End If
                [/red]
            Case FILE_ACTION_RENAMED_NEW_NAME
            Case FILE_ACTION_RENAMED_OLD_NAME
            Case Else
        End Select

What I'm trying to do is get away from polling as suggested. I'm going to be looking for a text file to be added to a folder to indicate some access tables are updating at which point I will disable some of the functionality of the application. When the updates are completed the file will be deleted and normal functionality will resume.

I'm currently polling a table in the backend every 5 seconds to check the value of a field.

Do you know if the API's will work in access? If not I'll move the app to VB. Thanks and enjoy the star.

I tried to have patience but it took to long! :) -DW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top