Example #1
0
 /// <summary>
 /// Sends null to all first points - all nodes reset their clear state.
 /// </summary>
 public void ClearGraphAsync()
 {
     Stop();
     lock (ClearingLock)
     {
         if (WasCleared)
         {
             return;
         }
         //if working when wait for work to finish
         ClearingEvent.WaitOne();
         StopingEvent.WaitOne();
         //TODO f**k
         //StartedEvent.WaitOne();
         //Start working (sending null
         ClearingEvent.Reset();
     }
     System.Diagnostics.Debug.WriteLine("Clearing");
     PrepareFlow();
     Last.ClearFilters();
     foreach (var lastNode in Last)
     {
         lastNode.OnFlow += OnLastFlow;
     }
     foreach (var first in First)
     {
         IColorable first1 = first;
         new Thread(() => first1.Flow(first1, null))
         {
             IsBackground = true
         }.Start();
     }
 }
Example #2
0
        public void StartAsync()
        {
            //enter only one thread
            lock (StartingLock)
            {
                //if working when wait for work to finish
                StartedEvent.WaitOne();
                //Start working
                StartedEvent.Reset();
            }
            GetStartColors();
            if (NodesToNotify.FilteredCount == NodesToNotify.Count)
            {
                if (NodesToNotify.Count == 0)
                {
                    Finish();
                }
                return;
            }
            Stop();
            ClearGraph();
            System.Diagnostics.Debug.WriteLine("Starting");
            WasCleared = false;
            WasStoped  = false;
            PrepareFlow();
            NodesToNotify.ClearFilters();
            foreach (var notifyNode in NodesToNotify)
            {
                notifyNode.OnNotifyBack += OnNotifyNodeFinished;
            }
            //Set onNotifyBackEvent for all nodes
            if (OnGlobalError != null)
            {
                Traverse(First, current => current.GetNextPaths(), current =>
                {
                    var colorableClass =
                        current as ColorableClass;
                    if (colorableClass != null)
                    {
                        colorableClass.OnNotifyBack +=
                            InvokeGlobalError;
                    }
                },
                         null);
            }
            foreach (var first in First)
            {
                IColorable first1 = first;

                Color color;
                if (StartColors.ContainsKey(first))
                {
                    color = StartColors[first];
                }
                else
                {
                    color = null;
                }
                new Thread(() => first1.Flow(first1, color))
                {
                    IsBackground = true
                }.Start();
            }
        }