我如何能安排在一个WinForms应用程序的任务? [英] How can I schedule tasks in a WinForms app?

查看:153
本文介绍了我如何能安排在一个WinForms应用程序的任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问:我如何能安排在一个WinForms应用程序的任务?要么是(一)什么是最好的方法/ .NET类/方法使用的(B),如果有,这是否还有哪些人会推荐一个开源组件。

QUESTION: How can I schedule tasks in a WinForms app? That is either (a) what is the best approach / .NET classes/methods to use of (b) if there is an open source component that does this well which one would be recommended.

背景:

  • 在Winforms应用程序(.NET v3.5版本,C#,VS2008)
  • 在我假设我将要运行的WinForms应用程序始终,只是最小化到系统托盘在不使用时
  • 希望有一个简单的方法(没有想进入单独的服务运行UI的WinForms应用程序会谈等)
  • 希望能够让用户选择的频率来安排同步(例如每小时,每日 - 挑时间等)
  • 在有能力的时候,调度火运行的code一大块(假设它可以被包装成一个BackgroundWorker任务为例)
  • 应用程序总是处于运行状态和放大器;将出现在系统托盘中

推荐答案

如果您不希望Windows服务,然后启动应用程序与Windows我的选择。您可以使用下面的code做到这一点。

If you don't want a Windows service then starting the application with windows i an option. you can use the following code to do that.

Dim regKey As RegistryKey
regKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
regKey.SetValue(Application.ProductName, Application.ExecutablePath)
regKey.Close()

那你按计划指的是同步?原来是这样一个差异服务?然后,您可以使用计时器,然后存储在一个XML文件或数据库中的用户设置。如果你想要一个简单的存储,那么你可以使用 My.Settings

编辑:我认为唯一的办法是检查的日期时,应用程序启动,然后定期检查的日期。另一种选择是使用编程任务调度。 任务计划托管包装是一个开放源码的包装,你可以尝试一下。

I think only way is to check for the date when the app starts and then check the date periodically. Another option is to use the task scheduler programatically. Task Scheduler Managed Wrapper is an open source wrapper which you can try out.

这篇关于我如何能安排在一个WinForms应用程序的任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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