How can I schedule tasks in a WinForms app?

后端 未结 3 581
情书的邮戳
情书的邮戳 2020-12-16 05:17

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 componen

3条回答
  •  误落风尘
    2020-12-16 06:05

    If you don't want a Windows service then starting the application with windows is 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()
    

    What did you mean by schedule the sync? Is it a diff service? Then you can use the timer and then store the user settings in an xml file or a DB. If you want a simple storage then you can use My.Settings.

    Edit: I think the 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.

提交回复
热议问题