C# 为什么从TaskScheduler运行时会出现Win32Exception?

C# 为什么从TaskScheduler运行时会出现Win32Exception?,c#,scheduled-tasks,win32exception,C#,Scheduled Tasks,Win32exception,仅当我从TaskScheduler运行时,才会出现异常: static class Program { [STAThread] static void Main(string[] args) { Application.Run(new Master()); } } public partial class Master : Form { public Master() // EXCEPTION OCCURS HERE {

仅当我从TaskScheduler运行时,才会出现异常:

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

public partial class Master : Form
{

   public Master()  //  EXCEPTION OCCURS HERE
   {

   }
}
任务计划程序:

Run whether user logged in or not : Checked 
Run with highest privileges : Checked
System.ComponentModel.Win32异常未处理 HResult=-2147467259 Message=找不到指定的过程 Source=System.Windows.Forms 错误代码=-2147467259 NativeErrorCode=127 堆栈跟踪: 在System.Windows.Forms.NativeWindow.WindowClass.RegisterClass()中 位于System.Windows.Forms.NativeWindow.WindowClass.Create(字符串类名称,Int32类样式) 位于System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp) 在System.Windows.Forms.Control.CreateHandle()中 在System.Windows.Forms.Application.MarshalingControl..ctor()中 在System.Windows.Forms.Application.ThreadContext.get_MarshalingControl()中 在System.Windows.Forms.WindowsFormsSynchronizationContext..ctor()中 在System.Windows.Forms.WindowsFormsSynchronizationContext.InstallIfRequired()中 位于System.Windows.Forms.Control..ctor(布尔值autoInstallSyncContext) 在System.Windows.Forms.ScrollableControl..ctor()中 在System.Windows.Forms.ContainerControl..ctor()中 在System.Windows.Forms.Form..ctor()中 在FssClient.Master..ctor()处 位于FssClient.Program.Main(字符串[]args)
InnerException:

我想说,您在这里处于“无需隐藏”状态-如果您正在运行“无论用户是否登录”,那么您将在非交互式会话0中运行。因此,您将无法显示
表单
。从任务计划程序运行时,您的程序不会获得指定的图形上下文。Youi不能通过调度程序创建windows和其他GUI元素。事实上,我相信你可以。我经常这样做。这是可行的,但一夜之间发生了变化。我还有其他安排好的任务,表单运行得很愉快。在启动
WCF
时,我也面临同样的问题,有人能帮忙吗?