-1

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?

2 Answers2

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