VB Timer Control
-
I have created a secure shell in VB that sits in place of the desktop. In this shell there are a number of icons, which when clicked on run up the specified application. This then logs time spent in the application. When it finishes I then just note the time down and work out the elapsed time. However to find when the application finishes I have created a loop that checks whether the application has terminated. So far so good. But now the problem I have is that every 15 minutes I want to create a file of the time spent in each of the applications and send it off to another machine. The timer control in VB will only go on for 1 minute before having to reset it, so thats not really good. I could implement a C++ program to run a timer but then I have the problem in intergrating the two codes together, as the C++ will not know the contents of the variables in the VB application. I had thought about writing the data out to a file as I go (created and opened in the VB code), but then the C++ timer could cause problems in trying to close the file down, and also I would not be able to rest the variables in the VB code easily. Obviously I would like to keep all the code in VB if I could. Also does the timer allow you to come out of the loop that I may be in whilst waiting for a currently running application to finish, and then go back into the loop. Any help would be great. Thanks Simon Kearn (simon.kearn@lmco.com or simon.kearn@ntlworld.com)
-
I have created a secure shell in VB that sits in place of the desktop. In this shell there are a number of icons, which when clicked on run up the specified application. This then logs time spent in the application. When it finishes I then just note the time down and work out the elapsed time. However to find when the application finishes I have created a loop that checks whether the application has terminated. So far so good. But now the problem I have is that every 15 minutes I want to create a file of the time spent in each of the applications and send it off to another machine. The timer control in VB will only go on for 1 minute before having to reset it, so thats not really good. I could implement a C++ program to run a timer but then I have the problem in intergrating the two codes together, as the C++ will not know the contents of the variables in the VB application. I had thought about writing the data out to a file as I go (created and opened in the VB code), but then the C++ timer could cause problems in trying to close the file down, and also I would not be able to rest the variables in the VB code easily. Obviously I would like to keep all the code in VB if I could. Also does the timer allow you to come out of the loop that I may be in whilst waiting for a currently running application to finish, and then go back into the loop. Any help would be great. Thanks Simon Kearn (simon.kearn@lmco.com or simon.kearn@ntlworld.com)
Why now just write your reporting app (in VB of course) without any timer support, then just have the Windows Scheduler Service (Scheduled Tasks) kick off the app every 15 minutes. You could even schedule it to run between the hours of whatever to whatever and on what days. This would, of course, require that you keep your information in a file as it's being created... RageInTheMachine9532 "...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
-
I have created a secure shell in VB that sits in place of the desktop. In this shell there are a number of icons, which when clicked on run up the specified application. This then logs time spent in the application. When it finishes I then just note the time down and work out the elapsed time. However to find when the application finishes I have created a loop that checks whether the application has terminated. So far so good. But now the problem I have is that every 15 minutes I want to create a file of the time spent in each of the applications and send it off to another machine. The timer control in VB will only go on for 1 minute before having to reset it, so thats not really good. I could implement a C++ program to run a timer but then I have the problem in intergrating the two codes together, as the C++ will not know the contents of the variables in the VB application. I had thought about writing the data out to a file as I go (created and opened in the VB code), but then the C++ timer could cause problems in trying to close the file down, and also I would not be able to rest the variables in the VB code easily. Obviously I would like to keep all the code in VB if I could. Also does the timer allow you to come out of the loop that I may be in whilst waiting for a currently running application to finish, and then go back into the loop. Any help would be great. Thanks Simon Kearn (simon.kearn@lmco.com or simon.kearn@ntlworld.com)
Dim i as Integer 'In your init routine Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e _ As System.EventArgs) Handles Timer1.Tick i += 1 'Increment for each minute - Interval set to 60,000 If i > 14 Then 'Do your file stuff here as 15 minutes have elapsed i=0 End If End Sub If "to err is human", programmers must be superhuman...
-
Dim i as Integer 'In your init routine Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e _ As System.EventArgs) Handles Timer1.Tick i += 1 'Increment for each minute - Interval set to 60,000 If i > 14 Then 'Do your file stuff here as 15 minutes have elapsed i=0 End If End Sub If "to err is human", programmers must be superhuman...
Thanks for that. On the other issue; if I am in a loop at the time of the timer Interval expiring. Will I get returned back into the loop once the timer procedure has been completed. Can't seem to find any info on whether this will happen or not. Ta, Simes
-
Thanks for that. On the other issue; if I am in a loop at the time of the timer Interval expiring. Will I get returned back into the loop once the timer procedure has been completed. Can't seem to find any info on whether this will happen or not. Ta, Simes
You'll never actually leave the loop. You MUST put a Application.DoEvents in the loop, somewhere where it will execute fairly often, so your app will get the Timer Tick events and be able to process them. As a general rule, without the DoEvents, your app will stay in the loop and only execute the stacked up events when the loop terminates and the function that it's in gives up control to the GUI again. RageInTheMachine9532 "...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome