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

            Job.Job.Execute(this, Args.ThreadIndex, Job.Parameter);
        }
Esempio n. 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 (limitLock)
                {
                    //check thread limit
                    if (Limit > 0 && limitAvailale > 0)
                    {
                    }
                }

                lock (DispatchQueue.SyncRoot)
                {
                    if (DispatchQueue.Count == 0 || (DateTime.Now - LastExecute).TotalMilliseconds < ExecuteInterval)
                    {
                        goto workerWait;
                    }
                    Job = (JobItem)DispatchQueue.Dequeue();

                    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(16);
                continue;
            }
        }