关闭控制台应用程序窗口时停止计时 [英] stop timer while closing console application window

查看:393
本文介绍了关闭控制台应用程序窗口时停止计时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用dot net compact framework 2.0创建一个设备应用程序。在应用程序中有一个执行一些代码的system.threading.timer。它的工作正常。但我的问题是,当我通过双击exe文件运行应用程序,存在于bin文件夹中时,计时器启动并执行所有工作,但它永远不会停止。即使在通过单击X按钮或从文件菜单关闭按钮关闭应用程序后,它也会在后台运行。当我在调试模式下运行代码时它工作正常,当我停止程序时计时器停止。但不是在exe中工作。我不明白我如何以及在何处停止或处置计时器,以便在关闭应用程序后它不会运行,可能类似于窗体表单应用程序中的form_closing事件。我在谷歌搜索了很多,但没有得到任何正确的答案。

解决方案

我无法全面解决你的问题,因为我看不到你的代码,但也许你可以使用一些想法:

首先,看看这个问题的最佳答案: http://stackoverflow.com/questions/12117906/detect-when-console-is-being-closed [ ^ ]。



-SA

I am creating a device application using dot net compact framework 2.0. there is a system.threading.timer in application which execute some code. its works fine. but my problem is when i am running the app by double clicking the exe, present in bin folder, the timer starts and execute all it works but it never stops. it runs in background even after closing the app by clicking X-button or from file menu close button. its working fine when i run the code in debug mode,timer stopped when i stop the program. but not working in exe. I don't understand how and where do i stop or dispose the timer so that it doesn't run after closing the app, may be something like form_closing event in window form application. I had searched a lot in google but don't get any proper answer.

解决方案

I cannot comprehensively solve your problem because I don't see your code, but maybe you can use some ideas:
First, look at the top answer to this question: http://stackoverflow.com/questions/12117906/detect-when-console-is-being-closed[^].

—SA


这篇关于关闭控制台应用程序窗口时停止计时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆