Ejemplo n.º 1
0
 private async Task SetEvent(string eventStr)
 {
     if (eventStr == EnumEvent.Idle)
     {
         await Task.Delay(50);
     }
     m_CurrentEvent = eventStr;
     EventStatus?.Invoke(this, null);
 }
Ejemplo n.º 2
0
        public void Start(int port)
        {
            if (port < 0)
            {
                throw new ArgumentException($"{nameof(port)} is not be negative");
            }
            else if (_thread != null)
            {
                return;
            }
            else
            {
                _thread = new Thread(() =>
                {
                    _socket.Bind(new IPEndPoint(IPAddress.Any, port));

                    _socket.Listen(_maxQueue);

                    try
                    {
                        while (true)
                        {
                            EventStatus?.Invoke(ServerWaitStatus);

                            var client = _socket.Accept();

                            client.Close();
                        }
                    }
                    catch (SocketException)
                    {
                        EventStatus?.Invoke(ServerClosedStatus);
                    }
                });

                _thread.Start();
            }
        }