Beispiel #1
0
        /* .NET 3.5 only */

        public static void ForEach <TSource>(IEnumerable <TSource> source, Action <TSource> body)
        {
            ParameterizedThreadStart threadStart = (object x) => body((TSource)x);
            var ts = new List <Original.Thread>();

            try
            {
                foreach (var s in source)
                {
                    var t = new Original.Thread(threadStart);
                    ts.Add(t);
                    t.Start(s);
                }
            }
            finally
            {
                foreach (var t in ts)
                {
                    try { }
                    finally
                    {
                        t.Join();
                    }
                }
            }
        }
 public SimplePartitioner(ClrSyncManager manager,
                          long start, long end, long split, Func <long, T> get, bool keysNormalized) :
     base(false, false, keysNormalized)
 {
     this.manager     = manager;
     this.min         = start;
     this.max         = end - 1;
     this.split       = split;
     this.get         = get;
     this.forwardpos  = min;
     this.backwardpos = max;
     barrier          = new OThreading.Barrier(2);
     semaphore        = new OThreading.Semaphore(0, 1);
     mainthread       = OThreading.Thread.CurrentThread;
     //global::System.Console.WriteLine("SimplePartitioner constructed by " + OThreading.Thread.CurrentThread.ManagedThreadId);
 }
 private void HandleContinuousSoundRecognized(object sender, global::AuxiliaryLibrary.StringEventArgs e)
 {
     if (!clientBusy)
     {
         clientBusy   = true;
         clientThread = new global::System.Threading.Thread(new global::System.Threading.ThreadStart(() => SendMessage(e.StringValue)));
         clientThread.Start();
     }
     //    client.Send(e.StringValue);
     if (continuousSpeechRecognitionControl.ExtractDetectedSounds == true)
     {
         if (InvokeRequired)
         {
             this.BeginInvoke(new global::System.Windows.Forms.MethodInvoker(() => ShowContinuousRecognizedSound(e.StringValue)));
         }
         else
         {
             ShowContinuousRecognizedSound(e.StringValue);
         }
     }
 }
        // called by the child thread
        private IEnumerator <KeyValuePair <long, T> > EnumerateBackward()
        {
            childthread = OThreading.Thread.CurrentThread; // set this before barrier so main thread can read it after barrier
            global::System.Diagnostics.Debug.Assert(childthread != mainthread);

            // synchronize with main thread (first handshake)
            barrier.SignalAndWait();

            // synchronize with main thread (second handshake)
            barrier.SignalAndWait();

            manager.ThreadBegin(childthread);

            // capture thread
            for (long i = max; i >= split; i--)
            {
                T t = get(i);
                //MChessChess.TraceEvent("backward enum:" + i + ":" + t.ToString());
                yield return(new KeyValuePair <long, T>(i, get(i)));
            }

            // we're done ... terminate chess thread
            EndChildThread();
        }