C# Console Application - Keep it running

前端 未结 11 1725
萌比男神i
萌比男神i 2020-12-16 01:02

I am about to develop a console application that will be required to continually run and carry out work at specific times.

My question is what is are best methods or

11条回答
  •  失恋的感觉
    2020-12-16 01:52

    You can add a reference to System.Windows.Forms and call System.Windows.Forms.Application.Run() to begin a standard application message loop. Ctrl-C will terminate the app.

    Another option is to use Console.ReadKey() to pause the app. Like Console.WriteLine("Press [ANY] key to quit..."); Console.ReadKey();

    That's what I use in my console apps when they're just sitting there waiting for events to occur. In either case the app will continue to run and catch triggered events (like from a timer, WCF, FileWatcher, etc).

提交回复
热议问题