- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我想弄清楚我应该使用哪个。在关闭我的 WinForm 应用程序时,会在对话框模式下触发一个表单。该表单运行一个后台工作程序,该工作程序将数据库与远程数据库同步,并在“Splash Form”上显示它的进度。
我有这样一个方法:
private void CloseMyApp()
{
SaveUserSettings();
splashForm = new SplashForm();
splashForm.ShowDialog();
Application.ExitThread();
//Application.Exit();
}
这是我从 Menu --> Exit 和 Form_FormClosing()
事件中关闭我的应用程序时调用的。 Application.Exit()
给出以下错误 -->
Collection was modified; enumeration operation may not execute.
现在我读到 Environment.Exit()
很残酷,这意味着您的应用可能有问题(请参阅 here)。
Application.ExitThread()
有效,但我担心它可能只是表面上有效,因为我之前从未使用过它,所以我不确定通常什么时候适合这样做。
最佳答案
不幸的是,问题不是由任何这些引起的,并且在所有这些情况下都确实存在(即使您没有收到消息)。
你的问题是这样的:
On closing my WinForm App fires of a Form in Dialog mode. That form runs a Background worker that Syncs the DB with the remote DB and displays it's progress on the "Splash Form."
由于您在请求关闭时实际上并未关闭,因此所有“退出”函数都试图关闭您的后台线程。不幸的是,这可能发生在您的数据库同步过程中,并且在保存逻辑中工作的枚举可能会提供该错误。
我建议不要使用任何这些 - 只需调用 myMainForm.Close()
即可。那应该关闭您的主窗体,这将适本地触发您的关闭逻辑。一旦应用程序中的主窗体关闭,它将正常关闭。
关于c# - Application.Exit() 与 Application.ExitThread() 与 Environment.Exit(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1312885/
我的应用程序有一个使用 CreateThread 创建的线程。从所述线程中调用 ExitThread 和允许线程正常退出(即到达线程函数的末尾)之间有什么区别?我正在使用 C++ 和 Visual S
using System.Windows.Forms; public class App { [STAThread] public static void Main() {
我知道Exitthread 只能在Thread 内部调用,而Abort 可以随时随地使用,只要你能访问到Thread 对象。但是,当您需要强制关闭线程时,这两种方法(在操作方面)之间是否存在其他显着差
我想弄清楚我应该使用哪个。在关闭我的 WinForm 应用程序时,会在对话框模式下触发一个表单。该表单运行一个后台工作程序,该工作程序将数据库与远程数据库同步,并在“Splash Form”上显示它的
阅读 VS2008 帮助文件后,我发现退出线程(在 .net 中)的干净方法是使用返回语句(在 C# 中)或让线程到达方法的末尾。 但是,我还没有找到允许我设置线程退出代码的方法或属性,也没有找到检索
我是一名优秀的程序员,十分优秀!