Example #1
0
        static void Main(string[] args)
        {
            var preamble = new List <string>
            {
                "Hello there ... ctrl-c to quit",
                "------------------------------"
            };

            SimpleSplitScreenConsole.InitConsole(preamble, OnShutDown);

            var cancellationToken = _tokenSource.Token;

            var tasks = new Task[]
            {
                Task.Factory.StartNew(Consume, cancellationToken),
                Task.Factory.StartNew(Produce, cancellationToken)
            };

            try
            {
                Task.WaitAll(tasks);
            }
            catch (AggregateException aex)
            {
                SimpleSplitScreenConsole.OnResponse("Exception thrown: " + aex.Message);
            }
        }
Example #2
0
        private static void Produce()
        {
            while (!_tokenSource.IsCancellationRequested)
            {
                var message = SimpleSplitScreenConsole.FetchInput();

                if (message != "")
                {
                    _messages.Enqueue(message);
                }
            }
        }
Example #3
0
        private static void Consume()
        {
            while (!_tokenSource.IsCancellationRequested)
            {
                while (_messages.Count() > 0)
                {
                    if (_messages.TryDequeue(out string message))
                    {
                        SimpleSplitScreenConsole.OnResponse(message);
                    }
                }

                Thread.Sleep(500);
            }
        }