简体   繁体   English

C builder RAD 2010 RTL / VCL Application-> Terminate()函数不终止应用程序

[英]C builder RAD 2010 RTL/VCL Application->Terminate() Function NOT TERMINATING THE APPLICATION

I have a problem also described here: http://www.delphigroups.info/3/9/106748.html 我有一个问题也在这里描述: http//www.delphigroups.info/3/9/106748.html

I have tried almost all forms of placing Application->Terminate() func everywhere in the code, following and not 'return 0', 'ExitProcess(0)', 'ExitThread(0)', exit(0). 我已经尝试了几乎所有形式的代码中的Application-> Terminate()func,跟随而不是'return 0','ExitProcess(0)','ExitThread(0)',exit(0)。 No working variant closes the app. 没有工作变体关闭应用程序。 Instead the code after Application->Terminate() statement is running. 相反,Application-> Terminate()语句之后的代码正在运行。

I have two or more threads in the app. 我在应用程序中有两个或更多线程。 I tried calling terminate func in created after execution threads and in main thread. 我尝试在执行线程和主线程中创建调用terminate func。

Also this is not related (as far as I can imagine) with CodeGuard / madExcept (I have turned it off and on, no effect). 这也与CodeGuard / madExcept(我已关闭并打开,没有效果)无关(据我所知)。 CodeGuard turning also did not do success. CodeGuard转向也没有成功。

The only working code variant is to place Application->Terminate() call to any of any form button's OnClick handler. 唯一可用的代码变体是将Application-> Terminate()调用放置到任何表单按钮的OnClick处理程序中。 But this does not fit in my needs. 但这不符合我的需要。 I need to terminate in any place. 我需要在任何地方终止。

What I should do to terminate all the threads in C++ Builder 2010 application and then terminate the process? 我该怎么做才能终止C ++ Builder 2010应用程序中的所有线程,然后终止进程?

Application->Terminate() does not close application immediately, it only signals you want to close the application. Application-> Terminate()不会立即关闭应用程序,它只表示您要关闭应用程序。

Terminate calls the Windows API PostQuitMessage function to perform an orderly shutdown of the application. 终止调用Windows API PostQuitMessage函数以执行应用程序的有序关闭。 Terminate is not immediate. 终止不是立竿见影的。

In your functions call Application->ProcessMessages() then check if the Application->Terminated property is true. 在函数中调用Application-> ProcessMessages(),然后检查Application-> Terminated属性是否为true。

For applications using calculation-intensive loops, call ProcessMessages periodically, and also check Terminated to determine whether to abort the calculation and allow the application to terminate 对于使用计算密集型循环的应用程序,请定期调用ProcessMessages,并检查Terminated以确定是否中止计算并允许应用程序终止

For example: 例如:

void Calc()
{
  for (int x = 0; x < 1000000; ++x)
  {
    // perform complex calculation

    // check if need to exit
    Application->ProcessMessages();
    if (Application->Terminated)
    {
      break;
    } // end if
  } // end for

  // clean up
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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