English 中文(简体)
透水池是否会带来一个时间背心功能,有时会同时安排不止一个路面?
原标题:Will the threadpool queue a timer s callback function, sometimes scheduling more than one thread at the same time?

在以下代码中<代码> 时间/标准 只应有一例。 这一呼吁书所援引的工人方法按顺序排列,,在时最多可操作一个读物。

www.un.org/Depts/DGACM/index_spanish.htm

如果电离层背后穿透镜(。 相对于单独read子()而言,说read子可能根据条件(已到达的MaxThreads,校对内部逻辑) que子并推迟实施是否正确?

Question Part 2:

假设可以就立即执行以外的任何事项提出一次时间要求回击,这是否意味着可能同时执行任何数目的read击?

< Question Part 3

假设第2部分是真实的,这是否意味着以下的编码能够同时运作不止一个警示?

之所以问一米,是因为有千例这种班级使用多种邮联服务器。 I m还看到数据腐败与/ Do Work here的室外运行相一致。

Aside>

// Do work here internally works with a System.Collections.Dictionary and edits the values of y. It also removes some keys for a subsequent function that is called serially. That function is missing keys (x) that were previously present in the first call. I think this is because there is a race condition with the final statement obj.cleanupdata()

public class SystemTimerTest
   {

    readonly System.Timers.Timer timerRecalcStatistics;
    readonly System.Diagnostics.Stopwatch stopwatchForRecalcStatistics = new System.Diagnostics.Stopwatch();


    public SystemTimerTest(TimeSpan range, DataOverwriteAction action)
    {
        int recalculateStatisticsEveryXMillseconds = 1000;

        timerRecalcStatistics = new System.Timers.Timer(recalculateStatisticsEveryXMillseconds);
        timerRecalcStatistics.AutoReset = true;
        timerRecalcStatistics.Elapsed += new System.Timers.ElapsedEventHandler(TimerRecalcStatisticsElapsed);
        timerRecalcStatistics.Interval = recalculateStatisticsEveryXMillseconds;
        timerRecalcStatistics.Enabled = true;


        this.maxRange = range;
        this.hashRunningTotalDB = new HashRunningTotalDB(action);
        this.hashesByDate = new HashesByDate(action);
        this.dataOverwriteAction = action;
    }


    private void TimerRecalcStatisticsElapsed(object source, System.Timers.ElapsedEventArgs e)
    {
        stopwatchForRecalcStatistics.Start();
        Console.WriteLine("The TimerRecalcStatisticsElapsed event was raised at {0}", e.SignalTime.ToString("o"));

         // DO WORK HERE


        stopwatchForRecalcStatistics.Stop();
        double timeBuffer  = GetInterval(IntervalTypeEnum.NearestSecond, e.SignalTime) - stopwatchForRecalcStatistics.ElapsedMilliseconds;

        if (timeBuffer > 0)
            timerRecalcStatistics.Interval = timeBuffer;
        else
            timerRecalcStatistics.Interval = 1;

        stopwatchForRecalcStatistics.Reset();         
        timerRecalcStatistics.Enabled = true;
    }
 }
最佳回答

页: 1 (1) ThreadPool能否推迟执行回击方法,并不重要,因为任何回击都无法保证在另一个时间间隔时间之前完成执行(例如,可以通过透镜机中止翻新,或者可以称为长期运行功能)。

页: 1 2) 这就是MSDN有关

If the SynchronizingObject property is null, the Elapsed event is raised on a ThreadPool thread. If processing of the Elapsed event lasts longer than Interval, the event might be raised again on another ThreadPool thread. In this situation, the event handler should be reentrant.

因此,答案是YES,可同时在多个侧面上执行。

页: 1 3) YES。 你们要么避免在追随方法中使用共享资源(时间统计,停止对统计系统的监视),要么同步利用这些共有资源(例如,锁),要么对时间段 财产,或将时间的不动产设定为虚假(并能够在时间吸引力结束时再次出现)。

UPDATE: I thing that Jon Skeet s answer doesn t solve your problem. Also implementing your own SynchonizingObject is IMHO more complicated than necessary (but it s hard to say without knowing whole problem). I hope this implementation should work (but I didn t tested it):

public class MySynchronizeInvoke : ISynchronizeInvoke
{
    private object SyncObject = new Object();
    private delegate object InvokeDelegate(Delegate method, object[] args);

    public IAsyncResult BeginInvoke(Delegate method, object[] args)
    {
        ElapsedEventHandler handler = (ElapsedEventHandler)method;
        InvokeDelegate D = Invoke;
        return D.BeginInvoke(handler, args, CallbackMethod, null);
    }

    private void CallbackMethod(IAsyncResult ar)
    {
        AsyncResult result = ar as AsyncResult;
        if(result != null)
            ((InvokeDelegate)result.AsyncDelegate).EndInvoke(ar);
    }

    public object EndInvoke(IAsyncResult result)
    {
        result.AsyncWaitHandle.WaitOne();
        return null;
    }

    public object Invoke(Delegate method, object[] args)
    {
        lock(SyncObject)
        {
            ElapsedEventHandler handler = (ElapsedEventHandler)method;
            handler(args[0], (ElapsedEventArgs)args[1]);
            return null;
        }
    }

    public bool InvokeRequired
    {
        get { return true; }
    }
}
问题回答

http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx”rel=“nofollow”>关于系统的文件。

If the SynchronizingObject property is null, the Elapsed event is raised on a ThreadPool thread. If processing of the Elapsed event lasts longer than Interval, the event might be raised again on another ThreadPool thread. In this situation, the event handler should be reentrant.

回答你的问题:

  1. 是的,它穿透了透镜,并像任何其他东西一样,受到read合填充和推迟。 鉴于水池目前最多有数百条read,因此,这个问题就是一个问题。 如果是的话,你会遇到更大的问题。

  2. 假设你不设定同步目标,或以其他方式篡改你的呼吁,那么多回击可能会重叠。 如果你给予时间同步目标,不会重叠。

  3. 你提供的守则没有以任何方式同步进行,因此,可以有多个重叠之处,同时执行你的反馈。 如果你想让这几类人相互协调,或如果你想要每一类人时都只出现过一次退步,那么你就应当使用像24小时声明这样的方法。





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

热门标签