English 中文(简体)
2. 利用时间物体
原标题:using timer objects dynamically c#/.net

I wanted to see if anyone had any experience or tips on using timers dynamically. We need a windows service that will periodically check a text file. The text file will hold a market name and a start time. The service then needs to create a timer to perform a countdown and write out countdown information to an xml file... like 23minutes

all of that works now on a windows app for one timer and one countdown...we now want to make this dynamic...

这样,当服务开始时,它将为每个市场/交易时间创造时间......(前菲克斯·10am、芝加哥11:45pm等)。

然后,这项服务将检查任何新条目的文本档案...... 因此,如果该档案有菲克斯、芝加哥,然后是纽约,我们就希望该档案能够使菲尼克斯和芝加哥时代的人能够运行,然后开始纽约的时间。

不仅不能确定在服务下工作的多重时间者会如何互动,而且当他们都需要写到同一个Xml档案时,翻新会如何发挥作用。

对此有什么想法?

最佳回答

不仅不能确定在服务下工作的多重时间者会如何互动,而且当他们都需要写到同一个Xml档案时,翻新会如何发挥作用。

对此有什么想法?

它赢得了出色的工作。

管道被排在地下室。 翻新池只会产生一定数量的活性胎面:

http://msdn.microsoft.com/en-us/library/0ka9477y.aspx

只能由现有记忆来限制可上下层的作业数量;然而,透镜限制了能够同时积极参与这一进程的深层。

此外,从多个透镜上写到同一档案,将会给你带来不良结果。

更不用说,如果你有所有这些read子,就更难以说明你的申请。

www.un.org/Depts/DGACM/index_spanish.htm 更简单的做法

1. 利用现有的时间,在不使用透镜的基础上建立自己的时间制度。

  • Create a structure defining a countdown entry.

法典:

public class Countdown
{
    public DateTime Time { get; set; }
    public event Action Elapsed { get; set; }

    public void RaiseElasped()
    {
        if(Elapsed != null)
            Elapsed();
    }
}
  • 阅读你的档案并创建:Dictionary<string,countdown>(名称->sdown)。 在你们将要采取的每一项行动中,规定相同的准则。

  • Create a FileSystemWatcher to look for changes to your input file. When the file is triggered, modify the dictionary as necessary.

  • 1. 创造一分钟的解决办法。

  • 每当这名计时员启动时,都要在字典上检查每件物品。 如果目标时间已经过去,请打电话RaiseElapsed。 (可能将其从独裁者中删除?)

From this point, it is hard to determine exactly what you d want to do, because you didn t describe what gets written to a file, when it happens, how often, or what happens once your countdown has elapsed. You should be able to figure out the rest yourself, though.

这种做法的好处是,单一阅读的方案更容易被 de弄,而且你获得你询问的任何问题(目前档案的存取,或太多的线索)。

The disadvantage is that it might bog down when you have a lot of entries. But if you have a lot of entries, you should really be using a database instead of of files.

问题回答

您可维持<代码>Dictionary<string,Datetime>,持有市场名称和时间。 定期间隔(每分钟一次?) 您可以通过字典进行扫描,仅使用日期计算过的时间。 减去,并将结果写到您的产出档案中。 http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx%20Stopwatch%20class”rel=“nofollow” 停止观察班





相关问题
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. ...

热门标签