简体   繁体   中英

Is there any way to prevent console application to close?

Is there any way to prevent console application to close ?

(that the user can't close the program)

Take a look at the Win32 console API .

You could try creating a windows (non console app) and then create your own console window with AllocConsole(). As I haven't tried this I can't say if Windows will still try to kill your process.

An alternative would be to create a background process/service to do the work.

Normally a console application can be aborted by pressing CTRL-C.

You can prevent CTRL-C from aborting your application by setting the Console.TreatControlCAsInput property or handling the Console.CancelKeyPress event .

Of course this won't stop the user from being able to kill your process, eg using Task Manager.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM