In general, there is an interesting method System.Windows.Forms.Application.Run () (without arguments!). when it is called, the main application thread "hangs" pending and "leaves" only when Application.Exit ().

I throw an app on an Asp.net server where Application.Run () cannot be used. And the application is key built on it.

So the question is: without System.Windows.Forms, how can you achieve the same effect as Application.Run ()?

    2 answers 2

    Thread.Sleep (Timeout.Infinite);

    or if you need to wait for completion from another thread - via EventWaitHandle

    • Thanks, I will dig there. understood - agehack0

    It all depends on the task you want to solve. Application.Run () starts a Windows message processing loop inside itself, which runs until it receives an application termination command. Bleeding messages from the queue can be done using the Application.DoEvents () method. You can call this method in a loop. Again, not knowing exactly what effect you want to achieve, it is difficult to advise something.

    • the problem is to start the application in a "hanging" state without using System.Windows.Forms.dll. - agehack0
    • one
      then it is best to arrange it as a service. Or write your own message processing loop while (! NeedClose) {Application.DoEvents ();} - ganouver