예제 #1
0
 /// <summary>
 /// Handles the SetCompleted event of the m_gate control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="DCalcCore.Utilities.QueueEventArgs"/> instance containing the event data.</param>
 private void m_gate_SetCompleted(Object sender, QueueEventArgs e)
 {
     /* Forward the set to the user */
     if (QueuedWorkCompleted != null)
     {
         QueuedWorkCompleted(this, new ScriptQueueEventArgs((IScript)sender, e.OutputSet, e.SetId));
     }
 }
예제 #2
0
파일: WorkQueue.cs 프로젝트: pavkam/school
        /// <summary>
        /// Work Queue thread method.
        /// </summary>
        private void WorkQueueMethod()
        {
            try
            {
                while (true)
                {
                    QueueEventArgs eventArgs = null;
                    WorkQueueItem nextItem = null;
                    Boolean shouldSleep = false;

                    lock (m_SyncRoot)
                    {
                        nextItem = GetNext();

                        if (nextItem != null)
                        {
                            ScalarSet outSet = null;

                            if (!nextItem.Cancelled)
                            {
                                try
                                {
                                    outSet = nextItem.CompiledScript.Execute(nextItem.InputSet);
                                }
                                catch
                                {
                                }

                                eventArgs = new QueueEventArgs(outSet, nextItem.InputSet.Id);
                            }
                        }
                        else
                            shouldSleep = true;
                    }

                    if (shouldSleep)
                        Thread.Sleep(10); /* Sleep 10ms if there's nothing to work on */
                    else if (eventArgs != null)
                    {
                        if (QueuedWorkCompleted != null)
                        {
                            QueuedWorkCompleted(nextItem.Script, eventArgs);
                        }
                    }
                }
            }
            catch
            {
                return;
            }
        }