I have searched google for this and read some resources but I wasn't able to find a good answer. Does anyone know how to prevent the winform App window from opening when it is started by the task scheduler?
Asked
Active
Viewed 523 times
-1
-
1Setting your main form's `Visible` to `false` should do the trick – sallushan Jun 13 '14 at 15:13
-
@sallushan I believe OP wants to know if app was started by Task Scheduler or user. – 001 Jun 13 '14 at 15:19
-
Odd question, most programmers want to know how to make it *visible*. The task scheduler runs programs using its own desktop by default. Have you actually tried this or do you just assume it is going to be a problem? – Hans Passant Jun 13 '14 at 15:19
-
@ Hans Passant I had tried it ! – facebook-100002276297329 Jun 13 '14 at 15:25
-
I have solved it http://stackoverflow.com/questions/6568736/how-do-i-set-a-windows-scheduled-task-to-run-in-the-background – facebook-100002276297329 Jun 14 '14 at 01:52
2 Answers
1
You can hide the form in the Shown event like this:
this.Shown += new System.EventHandler(this.Form1_Shown);
private void Form1_Shown(object sender, EventArgs e)
{
Hide();
}

jmelhus
- 1,130
- 2
- 12
- 28
1
Try using command line arguments:
static class Program {
[STAThread]
static void Main() {
if (Environment.GetCommandLineArgs().Contains(@"/fromTask")) {
// run something else...
} else {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
When you schedule your program in the Task Scheduler, be sure to include the argument /fromTask
.

LarsTech
- 80,625
- 14
- 153
- 225
-
thank you .I have found a answer http://stackoverflow.com/questions/6568736/how-do-i-set-a-windows-scheduled-task-to-run-in-the-background – facebook-100002276297329 Jun 14 '14 at 01:58
-
@facebook-100002276297329 Your question didn't seem to be about *how* to use the Task Scheduler. – LarsTech Jun 14 '14 at 02:11
-