久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <bdo id='zm4ru'></bdo><ul id='zm4ru'></ul>
  • <small id='zm4ru'></small><noframes id='zm4ru'>

    <legend id='zm4ru'><style id='zm4ru'><dir id='zm4ru'><q id='zm4ru'></q></dir></style></legend>
  • <i id='zm4ru'><tr id='zm4ru'><dt id='zm4ru'><q id='zm4ru'><span id='zm4ru'><b id='zm4ru'><form id='zm4ru'><ins id='zm4ru'></ins><ul id='zm4ru'></ul><sub id='zm4ru'></sub></form><legend id='zm4ru'></legend><bdo id='zm4ru'><pre id='zm4ru'><center id='zm4ru'></center></pre></bdo></b><th id='zm4ru'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zm4ru'><tfoot id='zm4ru'></tfoot><dl id='zm4ru'><fieldset id='zm4ru'></fieldset></dl></div>

    <tfoot id='zm4ru'></tfoot>

      1. 在 Win32 上處理 CTRL+C

        Handle CTRL+C on Win32(在 Win32 上處理 CTRL+C)

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

          • <legend id='jGYP9'><style id='jGYP9'><dir id='jGYP9'><q id='jGYP9'></q></dir></style></legend>

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

                  <tfoot id='jGYP9'></tfoot>
                  <i id='jGYP9'><tr id='jGYP9'><dt id='jGYP9'><q id='jGYP9'><span id='jGYP9'><b id='jGYP9'><form id='jGYP9'><ins id='jGYP9'></ins><ul id='jGYP9'></ul><sub id='jGYP9'></sub></form><legend id='jGYP9'></legend><bdo id='jGYP9'><pre id='jGYP9'><center id='jGYP9'></center></pre></bdo></b><th id='jGYP9'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='jGYP9'><tfoot id='jGYP9'></tfoot><dl id='jGYP9'><fieldset id='jGYP9'></fieldset></dl></div>

                    <tbody id='jGYP9'></tbody>
                  本文介紹了在 Win32 上處理 CTRL+C的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我在 Win32 C++ 控制臺(tái)程序中處理 CTRL+C 事件時(shí)遇到一些問題.

                  I have some problems with the handling of CTRL+C events, in a Win32 C++ console program.

                  基本上我的程序是這樣的:(基于另一個(gè)問題:Windows Ctrl-C - 清理命令行應(yīng)用程序中的本地堆棧對(duì)象)

                  Basically my program looks like this: (based on this other question: Windows Ctrl-C - Cleaning up local stack objects in command line app)

                  bool running;
                  
                  int main() {
                  
                      running = true;
                      SetConsoleCtrlHandler((PHANDLER_ROUTINE) consoleHandler, TRUE);
                  
                      while (running) {
                         // do work
                         ...
                      }
                  
                      // do cleanup
                      ...
                  
                      return 0;
                  }
                  
                  bool consoleHandler(int signal) {
                  
                      if (signal == CTRL_C_EVENT) {
                  
                          running = false;
                      }
                      return true;
                  }
                  

                  問題是根本沒有執(zhí)行清理代碼.

                  The problem is the cleanup code not being executed at all.

                  處理函數(shù)執(zhí)行后,進(jìn)程終止,但在主循環(huán)后不執(zhí)行代碼.怎么了?

                  After the execution of the handler function the process is terminated, but without execute the code after the main loop. What's wrong?

                  根據(jù)要求,這是一個(gè)類似于我的程序的最小測(cè)試用例:http://pastebin.com/6rLK6BU2

                  as requested, this is a minimal test case similar to my program: http://pastebin.com/6rLK6BU2

                  我的輸出中沒有test cleanup-instruction"字符串.

                  I don't get the "test cleanup-instruction" string in my output.

                  我不知道這是否重要,我正在使用 MinGW 進(jìn)行編譯.

                  I don't know if this is important, I'm compiling with MinGW.

                  EDIT 2: 測(cè)試用例程序的問題是 Sleep() 函數(shù)的使用.沒有它,程序會(huì)按預(yù)期工作.

                  EDIT 2: The problem with the test case program is the use of the Sleep() function. Without it the program works as expected.

                  在 Win32 中,函數(shù)處理程序在另一個(gè)線程中運(yùn)行,因此當(dāng)處理程序/線程結(jié)束其執(zhí)行時(shí),主線程正在休眠.大概這就是進(jìn)程中斷的原因?

                  In Win32 the function handler runs in another thread, so when the handler/thread ends its execution the main thread is sleeping. Probably this is the cause of process interruption?

                  推薦答案

                  以下代碼對(duì)我有用:

                  #include <windows.h> 
                  #include <stdio.h> 
                  
                  BOOL WINAPI consoleHandler(DWORD signal) {
                  
                      if (signal == CTRL_C_EVENT)
                          printf("Ctrl-C handled
                  "); // do cleanup
                  
                      return TRUE;
                  }
                  
                  int main()
                  {
                      running = TRUE;
                      if (!SetConsoleCtrlHandler(consoleHandler, TRUE)) {
                          printf("
                  ERROR: Could not set control handler"); 
                          return 1;
                      }
                  
                      while (1) { /* do work */ }
                  
                      return 0;
                  }
                  

                  這篇關(guān)于在 Win32 上處理 CTRL+C的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  In what ways do C++ exceptions slow down code when there are no exceptions thown?(當(dāng)沒有異常時(shí),C++ 異常會(huì)以何種方式減慢代碼速度?)
                  Why catch an exception as reference-to-const?(為什么要捕獲異常作為對(duì) const 的引用?)
                  When and how should I use exception handling?(我應(yīng)該何時(shí)以及如何使用異常處理?)
                  Scope of exception object in C++(C++中異常對(duì)象的范圍)
                  Catching exceptions from a constructor#39;s initializer list(從構(gòu)造函數(shù)的初始化列表中捕獲異常)
                  Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區(qū)別)
                • <i id='x6Sw3'><tr id='x6Sw3'><dt id='x6Sw3'><q id='x6Sw3'><span id='x6Sw3'><b id='x6Sw3'><form id='x6Sw3'><ins id='x6Sw3'></ins><ul id='x6Sw3'></ul><sub id='x6Sw3'></sub></form><legend id='x6Sw3'></legend><bdo id='x6Sw3'><pre id='x6Sw3'><center id='x6Sw3'></center></pre></bdo></b><th id='x6Sw3'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='x6Sw3'><tfoot id='x6Sw3'></tfoot><dl id='x6Sw3'><fieldset id='x6Sw3'></fieldset></dl></div>

                        <tbody id='x6Sw3'></tbody>

                        <bdo id='x6Sw3'></bdo><ul id='x6Sw3'></ul>

                          • <small id='x6Sw3'></small><noframes id='x6Sw3'>

                            <tfoot id='x6Sw3'></tfoot>
                            <legend id='x6Sw3'><style id='x6Sw3'><dir id='x6Sw3'><q id='x6Sw3'></q></dir></style></legend>
                            主站蜘蛛池模板: 一区中文字幕 | 欧美色偷拍 | 妞干网av | av看片网站| 日韩中文字幕 | 美女国产精品 | 天天天插| 91精品国产色综合久久 | 国产资源视频 | 草在线| 日韩成年人视频在线 | 欧美久久久久久久久 | 天天干狠狠操 | 二区三区视频 | 一区二区视频 | 一区二区三区四区免费在线观看 | 国产精品久久久久影院色老大 | 高清一区二区三区 | 欧美三级三级三级爽爽爽 | 一本久久a久久精品亚洲 | 天天操天天干天天爽 | 久久久999免费视频 999久久久久久久久6666 | 日韩av在线不卡 | 亚洲欧美激情精品一区二区 | 国产精品视频久久久久 | 国产999精品久久久久久绿帽 | 亚洲日日夜夜 | 毛片在线看片 | 欧美色999 | 日韩三区在线观看 | 欧美综合一区二区三区 | 福利一区在线观看 | 国产精品免费一区二区三区四区 | 日韩高清一区 | 亚洲高清在线 | 中文字幕亚洲区一区二 | 成人精品毛片国产亚洲av十九禁 | 成人网在线观看 | 91视频官网 | 欧美专区日韩专区 | 国产精品久久久久久久7777 |