2

I get an exception ONLY when I run from TaskScheduler:

static class Program
{
    [STAThread]
    static void Main(string[] args)
     {
        Application.Run(new Master());
     }
}

public partial class Master : Form
{

   public Master()  //  EXCEPTION OCCURS HERE
   {

   }
}

Task Scheduler:

Run whether user logged in or not : Checked 
Run with highest privileges : Checked

System.ComponentModel.Win32Exception was unhandled HResult=-2147467259 Message=The specified procedure could not be found Source=System.Windows.Forms ErrorCode=-2147467259 NativeErrorCode=127 StackTrace: at System.Windows.Forms.NativeWindow.WindowClass.RegisterClass() at System.Windows.Forms.NativeWindow.WindowClass.Create(String className, Int32 classStyle) at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp) at System.Windows.Forms.Control.CreateHandle() at System.Windows.Forms.Application.MarshalingControl..ctor() at System.Windows.Forms.Application.ThreadContext.get_MarshalingControl() at System.Windows.Forms.WindowsFormsSynchronizationContext..ctor() at System.Windows.Forms.WindowsFormsSynchronizationContext.InstallIfNeeded() at System.Windows.Forms.Control..ctor(Boolean autoInstallSyncContext) at System.Windows.Forms.ScrollableControl..ctor() at System.Windows.Forms.ContainerControl..ctor() at System.Windows.Forms.Form..ctor() at FssClient.Master..ctor() at FssClient.Program.Main(String[] args) InnerException:

ManInMoon
  • 6,795
  • 15
  • 70
  • 133
  • I'd say you're on a hiding to nothing here - if you're running "whether user logged in or not" then you'll run in session 0 which is non-interactive. So you won't be able to show a `Form`. – Damien_The_Unbeliever Jun 18 '15 at 10:43
  • When running from the Task Scheduler, your program doesn't get a graphical context assigned. Youi cannot create windows and other GUI elements through the scheduler. – steenbergh Jun 18 '15 at 10:44
  • Actually - I believe you can. I do this quite a lot. This WAS working but something changed overnight. I have other scheduled tasks with forms that are running happily. – ManInMoon Jun 18 '15 at 10:48
  • I am also facing the same issue while starting ```WCF```, Can anyone help ? – Dipak Telangre Jan 09 '17 at 10:12

0 Answers0