Esempio n. 1
0
        /// <summary>
        /// Function used in the thread standard.
        /// </summary>
        private void FctThreadProcesserStandard()
        {
            IsRunningStandard = true;

            while (IsRunningStandard == true)
            {
                try
                {
                    Global.Log.WriteEvent(LogType.debug, string.Format("[PROCESSER:STD] Scanning standard queue..."));

                    // check if the queue is empty
                    if (QueueStandard.IsEmpty() == false)
                    {
                        // give all the elements in the queue and dispach it
                        ArrayList queuedObject = QueueStandard.GiveSpooledObject(StateSpooledObject.queued);

                        foreach (SpooledObject Object in queuedObject)
                        {
                            QueueStandard.ModifyState(Object.Name, StateSpooledObject.dispacher);
                            _dispacher.AddToDispacher(Object);
                        }
                    }

                    Global.Log.WriteEvent(LogType.debug, string.Format("[PROCESSER:STD] Next scan in {0} seconds", (float)_tempoThread / 1000));
                    Thread.Sleep(_tempoThread);
                }

                catch (ThreadAbortException)
                {
                }

                catch (Exception ex)
                {
                    Global.Log.WriteError("[PROCESSER:STD] " + ex.Message);
                    Global.Log.WriteError("[PROCESSER:STD] " + ex.StackTrace);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Function used in the thread.
        /// </summary>
        private void FctThreadDispacher()
        {
            IsRunning = true;

            while (IsRunning == true)
            {
                // find a free worker
                bool oneWorkerIsFree = false;

                while (oneWorkerIsFree == false)
                {
                    foreach (Worker work in _workers)
                    {
                        if (work.TaskToDo == null)
                        {
                            oneWorkerIsFree = true;
                            break;
                        }
                    }

                    Thread.Sleep(100);
                }

                _mutexSpooledObjects.WaitOne();

                try
                {
                    if (_spooledObjects.Count > 0)
                    {
                        for (int i = 0; i < _workers.Count; i++)
                        {
                            // dispach the spooled object to a free worker
                            if (((Worker)_workers[i]).TaskToDo == null)
                            {
                                SpooledObject toWork = (SpooledObject)_spooledObjects[0];
                                _spooledObjects.RemoveAt(0);


                                // modify state of object
                                switch (toWork.Type)
                                {
                                case TypeSpooledObject.standardMail:
                                {
                                    QueueStandard.ModifyState(toWork.Name, StateSpooledObject.sent);
                                } break;

                                case TypeSpooledObject.scheduledMail:
                                case TypeSpooledObject.scheduledTask:
                                {
                                    QueueScheduled.ModifyState(toWork.Name, StateSpooledObject.sent);
                                } break;
                                }


                                Global.Log.WriteEvent(LogType.normal, string.Format("[DISPACHER] '{0}' is assigned to {1}", toWork.Name, ((Worker)_workers[i]).Name));

                                ((Worker)_workers[i]).TaskToDo = toWork;

                                break;
                            }
                        }
                    }
                }

                catch (ThreadAbortException)
                {
                }

                catch (Exception ex)
                {
                    Global.Log.WriteError("[DISPACHER] " + ex.Message);
                    Global.Log.WriteError("[DISPACHER] " + ex.StackTrace);
                }

                _mutexSpooledObjects.ReleaseMutex();
            }
        }