Beispiel #1
0
        private void ExecuteProxy(object Obj)
        {
            ThreadProxyArgs Args = (ThreadProxyArgs)Obj;
            JobItem         Job  = Args.Job;

            Job.Job.Execute(this, Args.ThreadIndex, Job.Parameter);
        }
Beispiel #2
0
        private void ThreadWork(object Param)
        {
            WorkerArgs WorkerArg   = (WorkerArgs)Param;
            int        i           = WorkerArg.ThreadIndex;
            DateTime   LastExecute = new DateTime(1970, 1, 1);
            JobItem    Job;

            while (State == DispatcherState.BUSY)
            {
                lock (DispatchQueue.SyncRoot)
                {
                    if ((DateTime.Now - LastExecute).TotalMilliseconds < ExecuteInterval)
                    {
                        goto workerWait;
                    }
                    if (DispatchQueue.Count == 0)
                    {
                        if (!finishFlag)
                        {
                            // call finished event
                            // and set flag
                            if (QueueEmptied != null)
                            {
                                finishFlag = true;
                                QueueEmptied(this);
                            }
                        }
                        goto workerWait;
                    }
                    Job        = (JobItem)DispatchQueue.Dequeue();
                    finishFlag = false;
                    if (Job.Repeats == -1 || (Job.Repeats--) > 0)
                    {
                        DispatchQueue.Enqueue(Job);
                    }
                }
                LastExecute = DateTime.Now;
                ThreadProxyArgs Args = new ThreadProxyArgs()
                {
                    ThreadIndex = i, Job = Job
                };
                if (Job.Wait)
                {
                    ExecuteProxy(Args);
                }
                else
                {
                    Thread Worker = new Thread(new ParameterizedThreadStart(ExecuteProxy));
                    try
                    {
                        Worker.Start(Args);
                    }
                    catch
                    {
                    }
                }
workerWait:
                Thread.Sleep(32);
                continue;
            }
        }