简体   繁体   English

如何在.Net 5.0 C# 或 F# 中编写定期运行的代码

[英]How to write Code that runs Periodically at certain intervals in .Net 5.0 C# or F#

I've written some Code in F# ( some in C# ) /.Net 5.0 and I am just running it as a console app currently and debugging it in visual studio.我已经在 F# (一些在 C# )/.Net 5.0 中编写了一些代码,我目前只是将它作为控制台应用程序运行并在 Visual Studio 中调试它。

I want it to我想要它

  • Run by itself - every hour between 7 am and 6 pm Monday to Friday自行运行 - 周一至周五上午 7 点至下午 6 点之间每小时运行一次
  • Be able to pause execution if need be.如果需要,可以暂停执行。

What approach should I take with this?我应该采取什么方法呢? When I was writing nodejs apps I used to put the command line command in to the windows scheduler.当我编写 nodejs 应用程序时,我曾经将命令行命令放入 windows 调度程序中。

Should I我是不是该

  • Use the windows scheduler and do it as a command line使用 windows 调度程序并将其作为命令行执行
  • Write a Windows Service that does it编写一个 Windows 服务来完成它
  • something else?别的东西?

I'm not sure what approach to take & I might be missing an approach that fits this task perfectly.我不确定要采取什么方法,我可能会错过一种完全适合这项任务的方法。

If you are using Windows to run the exe you can use the built in Task Scheduler.如果您使用 Windows 运行 exe,您可以使用内置的任务计划程序。 Regarding pausing the application, you can add a watcher to the app which will check for status before it runs.关于暂停应用程序,您可以向应用程序添加一个观察者,该观察者将在应用程序运行之前检查状态。 Eg looks at a database or a centralised config file.例如查看数据库或集中配置文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM