如何使用Timer时如何停止挂起VB.net应用程序 [英] how to stop hanging VB.net Application whenever use Timer

查看:389
本文介绍了如何使用Timer时如何停止挂起VB.net应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我使用计时器时停止挂起VB.net应用软件





实际上我的代码是每10秒软件自动检查并通过电子邮件发送给客户,但问题是每当用户可以访问每个表单时启动计时器,每次软件挂起时请帮助我如何以后台工作,因为我的电子邮件代码从客户数据库获取数据并在发送自动后每个电子邮件地址。





请帮助

How to Stop Hanging VB.net Application Software whenever i am using Timer


actually my code is every 10 Sec Software Auto Check and Email to Client but problem is whenever timer starts every time form can accessible by user, every time software is hanging please help me how can i need to work as backgroundly because my email code get data from customer database and after it send auto as per email address.


Please Help

推荐答案

听起来像你正在使用工具箱中的Timer。这是一个依赖于Events的计时器,以便通知您的应用程序Tick。这也意味着它完全在UI线程(应用程序启动的线程)上运行。当线程每10秒运行一次检查时,它无法执行其他操作,例如更新UI(重新绘制)并响应用户点击。



唯一的解决方案是将检查代码移动到后台线程。这可以通过删除您在表单上删除的Timer而不是使用 System.Threading.Timer [ ^ ]类。它的回调将使用ThreadPool线程来执行您的检查代码。
It sounds like you're using the Timer that's in the Toolbox. This is a timer that depends on Events in order to notify your application of the Tick. This also means it runs entirely on the UI thread (the thread your application started up on). When the thread is running your check every 10 seconds, it can't do other things, like update the UI (repaint it) and respond to user clicks.

The only solution to that is to move your checking code to a background thread. That is easily accomplished by removing the Timer you dropped on the form and instead use the System.Threading.Timer[^] class. It's callback will use a ThreadPool thread to execute your check code.


这篇关于如何使用Timer时如何停止挂起VB.net应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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