English 中文(简体)
C#Windows Service Intermitt 方法
原标题:C# Windows Service Intermittent Method Call

Scenario

我有一个C#Windows服务公司,主要负责一些事件,如果事件引发任何事情,它会执行一些任务。

The Thing...

......这些事件是监测进程,我需要在当天某些时候重新开始。

Question

在确切的时候,我能如何最好地完成这项任务?

Thoughts so far are:

1)To use a timer that checks what time it is every few minutes. 2)Something that isn t a timer and doesn t suck as an implementation.

帮助非常受赞赏。

最佳回答

从IsBackground = 真的开始,在服务时开始新的透镜。 这确保了你在服务中断时的read死,因此,你可以简单地开始并忘记。

在路面,使用无休止的通道(60*1000)进行重新启动,等待正确的时间。 重新启动很可能是在与IsBackground = 虚假的新版面上进行的,以防止你在服完重整之前停止服务(视窗允许关闭30个区)。 或者,你可以启动一个单独的重新启动进程。

问题回答

你们可以放弃在某一时间运行的时间,但我可能赞成以下做法。

while (!closing)
{
if (SomethingNeedsDoingNow()) { DoIt(); }

Thread.Sleep(1);
}

这样做只会耗尽任何资源,然后能够轻易地在任何时间将事件火上.到第二种微粒。

SomethingNeedsDoingNow,应当核对目前的时间,看看是否有任何事件需要发射。 如果你能够放弃较松散的贪.,那么你就可以为60秒睡觉。

如果你真的想要避免执行时间,那么一个选择是,一个定时的窗口,在你发射时杀死了你的处理。

那么,你可以随时投票,确保这些进程能够运行,如果不是开始的话。

还是给予一定时间,但又采取了另一种做法。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签