public void DoDemonstration()
        {
            // Two instances of the calculator are created.  One is named "Odd"
            // (it calculates the 1st, 3rd, 5th... values in the sequence) the
            // other is named "Even".  They message each other back and forth
            // with the latest two values and successively build the sequence.
            var limit = 1000;

            // Two channels for communication.  Naming convention is inbound.
            var oddChannel  = new Channel <IntPair>();
            var evenChannel = new Channel <IntPair>();

            using (ThreadFiber oddFiber = new ThreadFiber(), evenFiber = new ThreadFiber())
            {
                oddFiber.Start();

                var oddCalculator = new FibonacciCalculator(oddFiber, "Odd", oddChannel, evenChannel, limit);

                evenFiber.Start();

                new FibonacciCalculator(evenFiber, "Even", evenChannel, oddChannel, limit);

                oddCalculator.Begin(new IntPair(0, 1));

                oddFiber.Join();
                evenFiber.Join();
            }
        }
        public void AsyncStop()
        {
            ThreadFiber threadFiber = new ThreadFiber(new CommandQueue());

            threadFiber.Start();
            threadFiber.Enqueue(threadFiber.Dispose);
            threadFiber.Join();
        }
        public void RunThread()
        {
            ThreadFiber threadFiber = new ThreadFiber(new CommandQueue());

            threadFiber.Start();
            threadFiber.Dispose();
            threadFiber.Join();
        }
        public void DoDemonstration()
        {
            // We create a source to generate the quadratics.
            var sinkFiber = new ThreadFiber("sink");

            // We create and store a reference to 10 solvers,
            // one for each possible square term being published.
            var quadraticChannels = new IChannel <Quadratic> [10];

            // reference-preservation list to prevent GC'ing of solvers
            var solvers       = new List <QuadraticSolver>();
            var solvedChannel = new Channel <SolvedQuadratic>();

            for (var i = 0; i < quadraticChannels.Length; i++)
            {
                var fiber = new ThreadFiber("solver " + (i + 1));
                fiber.Start();

                quadraticChannels[i] = new Channel <Quadratic>();
                solvers.Add(new QuadraticSolver(fiber, quadraticChannels[i], solvedChannel));
            }


            var source = new QuadraticSource(quadraticChannels, quadraticChannels.Length, DateTime.Now.Millisecond);

            // Finally a sink to output our results.
            sinkFiber.Start();
            new SolvedQuadraticSink(sinkFiber, solvedChannel, quadraticChannels.Length);

            // This starts streaming the equations.
            source.PublishQuadratics();

            // We pause here to allow all the problems to be solved.
            sinkFiber.Join();

            Console.WriteLine("Demonstration complete.");
        }