c# - Detect when console application is closing/killed? -


i wanted make safe exit console application running on linux using mono can't find solution detect wether signal sent or user pressed ctrl+c.

on windows there kernel function setconsolectrlhandler job doesnt work on mono.

how closing event on console application safe exit ?

you need use mono.unixsignal, there's sample posted jonathan pryor : http://www.jprl.com/blog/archive/development/mono/2008/feb-08.html

there's shorter example on mono page: faq / technical / operating system questions / signal handling:

// catch sigint , sigusr1 unixsignal[] signals = new unixsignal [] {     new unixsignal (mono.unix.native.signum.sigint),     new unixsignal (mono.unix.native.signum.sigusr1), };  thread signal_thread = new thread (delegate () {     while (true) {         // wait signal delivered         int index = unixsignal.waitany (signals, -1);          mono.unix.native.signum signal = signals [index].signum;          // notify main thread signal received,         // can use things like:         //    application.invoke () gtk#         //    control.invoke on windows.forms         //    write pipe created unixpipes server apps.         //    use autoresetevent          // example, works gtk#             application.invoke (delegate () { receivedsignal (signal); });     }}); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -