• <bdo id='WGm7f'></bdo><ul id='WGm7f'></ul>
        <tfoot id='WGm7f'></tfoot>

        <small id='WGm7f'></small><noframes id='WGm7f'>

        <legend id='WGm7f'><style id='WGm7f'><dir id='WGm7f'><q id='WGm7f'></q></dir></style></legend>

      1. <i id='WGm7f'><tr id='WGm7f'><dt id='WGm7f'><q id='WGm7f'><span id='WGm7f'><b id='WGm7f'><form id='WGm7f'><ins id='WGm7f'></ins><ul id='WGm7f'></ul><sub id='WGm7f'></sub></form><legend id='WGm7f'></legend><bdo id='WGm7f'><pre id='WGm7f'><center id='WGm7f'></center></pre></bdo></b><th id='WGm7f'></th></span></q></dt></tr></i><div id='WGm7f'><tfoot id='WGm7f'></tfoot><dl id='WGm7f'><fieldset id='WGm7f'></fieldset></dl></div>
      2. 检测控制台应用程序何时关闭/终止?

        时间:2023-08-27
          <legend id='BTVl0'><style id='BTVl0'><dir id='BTVl0'><q id='BTVl0'></q></dir></style></legend>

            <tbody id='BTVl0'></tbody>

            <small id='BTVl0'></small><noframes id='BTVl0'>

          1. <tfoot id='BTVl0'></tfoot>
          2. <i id='BTVl0'><tr id='BTVl0'><dt id='BTVl0'><q id='BTVl0'><span id='BTVl0'><b id='BTVl0'><form id='BTVl0'><ins id='BTVl0'></ins><ul id='BTVl0'></ul><sub id='BTVl0'></sub></form><legend id='BTVl0'></legend><bdo id='BTVl0'><pre id='BTVl0'><center id='BTVl0'></center></pre></bdo></b><th id='BTVl0'></th></span></q></dt></tr></i><div id='BTVl0'><tfoot id='BTVl0'></tfoot><dl id='BTVl0'><fieldset id='BTVl0'></fieldset></dl></div>

              • <bdo id='BTVl0'></bdo><ul id='BTVl0'></ul>

                • 本文介绍了检测控制台应用程序何时关闭/终止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想为我的控制台应用程序安全退出,该应用程序将使用单声道在 linux 上运行,但我找不到解决方案来检测是否向其发送了信号或用户按下了 ctrl+c.

                  I wanted to make a safe exit for my console application that will be running on linux using mono but I can't find a solution to detect wether a signal was sent to it or the user pressed ctrl+c.

                  在 Windows 上,有一个内核函数 SetConsoleCtrlHandler 可以完成这项工作,但在单声道上不起作用.

                  On windows there is the kernel function SetConsoleCtrlHandler which does the job but that doesnt work on mono.

                  如何在我的控制台应用程序上获得关闭事件以安全退出它?

                  How do I get a closing event on my console application to safe exit it ?

                  推荐答案

                  你需要使用 Mono.UnixSignal,Jonathan Pryor 发布了一个很好的示例:http://www.jprl.com/Blog/archive/development/mono/2008/Feb-08.html

                  You need to use Mono.UnixSignal, there's a good sample posted by Jonathan Pryor : http://www.jprl.com/Blog/archive/development/mono/2008/Feb-08.html

                  Mono 页面上还有一个较短的示例:FAQ/技术/操作系统问题/信号处理:

                  There's also a shorter example on Mono page: FAQ / Technical / Operating System Questions / Signal Handling:

                  // Catch SIGINT and 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 for a signal to be delivered
                          int index = UnixSignal.WaitAny (signals, -1);
                  
                          Mono.Unix.Native.Signum signal = signals [index].Signum;
                  
                          // Notify the main thread that a signal was received,
                          // you can use things like:
                          //    Application.Invoke () for Gtk#
                          //    Control.Invoke on Windows.Forms
                          //    Write to a pipe created with UnixPipes for server apps.
                          //    Use an AutoResetEvent
                  
                          // For example, this works with Gtk#    
                          Application.Invoke (delegate () { ReceivedSignal (signal); });
                      }});
                  

                  这篇关于检测控制台应用程序何时关闭/终止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 Winforms 中包含控制台? 下一篇:控制台应用程序中的进度条

                  相关文章

                  最新文章

                    <small id='v41dS'></small><noframes id='v41dS'>

                      <bdo id='v41dS'></bdo><ul id='v41dS'></ul>
                  1. <legend id='v41dS'><style id='v41dS'><dir id='v41dS'><q id='v41dS'></q></dir></style></legend>
                  2. <tfoot id='v41dS'></tfoot>
                  3. <i id='v41dS'><tr id='v41dS'><dt id='v41dS'><q id='v41dS'><span id='v41dS'><b id='v41dS'><form id='v41dS'><ins id='v41dS'></ins><ul id='v41dS'></ul><sub id='v41dS'></sub></form><legend id='v41dS'></legend><bdo id='v41dS'><pre id='v41dS'><center id='v41dS'></center></pre></bdo></b><th id='v41dS'></th></span></q></dt></tr></i><div id='v41dS'><tfoot id='v41dS'></tfoot><dl id='v41dS'><fieldset id='v41dS'></fieldset></dl></div>