在 .net 桌面应用程序中设置超时
您好,我创建了一个小应用程序来移动一些文件并将它们放入数据库中。除了应用程序需要超时之外,这种方法运行良好。
如果我的应用程序在 2 小时内未完成任务,它会重新打开并锁定所有内容。我需要说的是,如果我的申请已开放 2 小时,请关闭它。
一个想法是您可以在应用程序中设置超时吗?我对此进行了谷歌搜索,并在 system.threading 中找到了一些关于 timeout=infinite 和 threading.sleep=200 的内容,但并不真正理解这一点。
另一个想法是使用计时器并计算 2 小时,然后调用 close 方法,这看起来有点作弊。
关于 C# 或 Vb 中超时的任何想法
遗憾的是,这不是针对数据库连接,这不是应用程序失败的地方。
Hi I have created a little application to move some files around and put them into a database. This is working well except that the application needs a timeout.
If my app has not completed the task within 2 hours it re opens and locks out everything. I need to say that if my application has been open for 2 hours close it.
One thought was can you set a time out in an application. I have had a google for this and found some stuff in system.threading about timeout=infinite and threading.sleep=200 but don't really understand this.
Another thought, is using the timer and counting up to 2 hours and then calling a close method, this seams like a bit of a cheat.
Any ideas on time out in either C# or Vb
Sadly this is not for a db connection this is not where the application is failing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只允许应用程序的一个实例同时运行怎么样?
我猜您正在安排运行:查看此代码,将其作为在不更改计划的情况下防止应用程序出现多个实例的方法。
请不要放弃你的互斥锁...;-)
HTH
What about allowing just one instance of your application to run at the same time?
I guess you are scheduling runs: have a look at this code as a way of preventing multiple instances of your application without changing the scheduling.
Please, don't abandon your Mutex... ;-)
HTH
还有另一种选择吗?设置一个标志来指示进程当前是否正在运行。
如果该进程正在运行,则不要启动第二个或关闭第一个,或者可以设置一个计时器并在几分钟后再次检查(?)
What about another option? Set a flag which says whether the process is currently running or not.
If the process is running then dont start the second one or close the first one or may be be set a timer and check again after few minutes(?)
也许 DbConnection/DbCommand 对象的超时更合适(看看 MSDN)
Maybe a timeout for the DbConnection/DbCommand objects is more appropriate (have a look at MSDN)