Windows服务和C# [英] Windows service and C#

查看:102
本文介绍了Windows服务和C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个Windows服务,其中包含几种不同的方法,发生的事情是我使该方法在某个时间运行,我的计时器间隔是每分钟.
但是我注意到,当我让该服务通宵运行时,这些方法不会被调用,我知道这是因为它应该制作文本文件,并附加运行日期(每天10:00). >
请告知该怎么办或可能导致此问题的原因.
谢谢大家.

Hi guys, I have a windows service with a couple of different methods, what happens is that I make the method run at a certain time, my timers interval is for every minute.
But I have notices that when I let the service run overnight, the methods does not get called, I know this because it should make text files, appended with the date it was run (which is at 10:00 everyday).

Please advise on what to do, or what might cause this issue.

Thanks guys.

推荐答案

所以您有一个Windows服务,它在那里运行计时器,每分钟检查一次时间?如果时间是10:00,请执行一些操作?那是对的吗?

如果是这样,我会说您在检查时间的方式上有一些错误,并且您的代码永远不会被击中.没有看到源头,就不可能确定地说

但是,为什么还要为此使用Windows服务?这完全浪费了资源,并且对于您想要实现的目标来说是一个过于复杂的解决方案.

只需创建一个执行您的操作的console \ windows窗体应用程序(无界面)即可.然后创建一个计划的任务,该任务在指定的时间运行您的应用程序-完成工作!

这是一种非常简单的方法,您可以消除计时器\时间检查方面的任何可能的错误-这就是任务计划程序正在为您执行的操作.
So you''ve got a windows service that sits there running a timer, checking the time once a minute? If the time is 10:00, then perform some action? Is that correct?

If so, I''d say you''ve got some error in the way you''re checking the time and your code is never being hit. Without seeing the source, it''s impossible to say for sure

However, why are you even using a windows service for this? It''s a complete waste of resource and an overly complex solution for what you want to achieve.

Just create a console\windows forms app (with no interface) that performs your actions. Then create a scheduled task that runs your application at the specified time - job done!

It''s a much simplier approach and you eliminate any possible errors in the timer \ time checking side of things - thats what the task scheduler is doing for you.


这篇关于Windows服务和C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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