C# Application.Run without Form

后端 未结 4 1712
忘掉有多难
忘掉有多难 2020-12-06 11:06

Is it possible to call Application.Run, but to not pass a form parameter, or is there an alternative if there’s no form to call?

The Run method doesn’t seem to have

4条回答
  •  攒了一身酷
    2020-12-06 11:27

    using System;
    using System.Windows.Forms;
    
    static class Program
       [STAThread]
       static void Main() {
          Application.Run(new myClass());
       }
    
       internal class myClass : ApplicationContext {
          public myClass() {
             Application.Run(new myWindow());
          }
       }
    }
    

    The problem here, though, is that something will have to call this instance of myClass and tell it to exit or else the program will just keep running even after all forms are closed. And calling ExitThread() in the constructor is ignored.

提交回复
热议问题