예제 #1
0
        public void Start(string hostname, int port)
        {
            if (client != null)
            {
                return;
            }

            if (TryToConnect(hostname, port))
            {
                Task.Factory.StartNew(() =>
                {
                    var messageDecoder = new MessageDecoder();
                    var stream         = client.GetStream();
                    try
                    {
                        while (client.Connected)
                        {
                            var message = messageDecoder.Decode(stream);
                            OnShadeSelected?.Invoke(this, new MessageEventArgs(message));
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        Stop();
                    }
                });
            }
        }
예제 #2
0
        private void Run()
        {
            var random          = new Random();
            var uiDrawerCounter = 1;
            var uiDrawer        = EnumUiDrawer.Console;

            while (IsStated)
            {
                var newShape = RandomShape(random);
                if (--uiDrawerCounter <= 0)
                {
                    var posibleValue = (EnumUiDrawer[])Enum.GetValues(typeof(EnumUiDrawer));
                    uiDrawer        = posibleValue.First(e => e != uiDrawer);
                    uiDrawerCounter = random.Next(2, 6);
                }
                OnShadeSelected?.Invoke(this, new ShapeSeletedEventArgs(newShape, uiDrawer));
                manualResetEvent.WaitOne(1000);
            }
        }