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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Task Scheduler 2

Status
Not open for further replies.

Boris10

IS-IT--Management
Jan 26, 2012
97
0
0
KE
Hi everyone, i am making an application that performs a back up and allows the user to set different time intervals to do the back up. My Application programmatically creates/updates/deletes tasks in the Windows Task Scheduler based on user input.

My plan is to package this application with a single userform available to the user. I m able to successfuly create a windows schedule programmatically. However, i am failing to figure out how to run the back up code, since the task scheduler requires an .exe file and my .exe file is an event driven form.

Would anyone have any ideas. Thank you
 
Plan on writing a console application instead of event driven form. The console application can be scheduled to run on windows task scheduler
 

I have programs similar to this. My solution is to use command line arguments to determine whether to show the GUI or not. When the program runs, in the Form_Load event the form is hidden:

Me.Hide()

Then the command line arguments are checked:

If Environment.GetCommandLineArgs.Length > 1 Then
Me.Visible = True
Me.Show()
Me.WindowState = FormWindowState.Normal
Else
Timer1.Enabled = True
End If

I have to code that needs executed in a Timer event.

To show the form, run the app with any command line argument at all. I typically use:

"<path to app>\app.exe" 1

To run the app without the GUI and the timer activated to run the code, just call it without any arguments:

"<path to app>\app.exe"

You can run the app with the GUI in Visual Studio by going to the Project menu, select the Debug tab and enter something in the "Command Line Arguments" box on the right.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
My approach is rather different. I create a SUB MAIN (with the optional command line parameters) in a separate class and set this as the start-up object. Then I can analyse the command line parameters (if any) and start the program accordingly. If the user interface is required then simply create and instance of the main form followed by Application.Run(mainform name). That way your code can run in an IF ELSE block creating the form only if necessary.

Since I'm currently setting up some new computers, I don't have VS installed and won't be able to produce an example much before mid-week (if you need one).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top