async void SocketWorker()
        {
            try
            {
                SimpleWebSocket socket = null;
                while (true)
                {
                    if (_disposed)
                    {
                        socket?.Dispose();
                        return;
                    }

                    FrameMessage sendNow = null;
                    lock (_lock)
                    {
                        if (_pendingSocket != null)
                        {
                            socket?.Dispose();
                            socket                = _pendingSocket;
                            _pendingSocket        = null;
                            _lastSentFrameMessage = null;
                        }

                        if (_lastFrameMessage != _lastSentFrameMessage)
                        {
                            _lastSentFrameMessage = sendNow = _lastFrameMessage;
                        }
                    }

                    if (sendNow != null && socket != null)
                    {
                        await socket.SendMessage(
                            $"frame:{sendNow.SequenceId}:{sendNow.Width}:{sendNow.Height}:{sendNow.Stride}:{sendNow.DpiX}:{sendNow.DpiY}");

                        await socket.SendMessage(false, sendNow.Data);
                    }

                    _wakeup.WaitOne(TimeSpan.FromSeconds(1));
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
            }
        }
        async void AcceptWorker()
        {
            while (true)
            {
                using (var req = await _simpleServer.AcceptAsync())
                {
                    if (!req.IsWebsocketRequest)
                    {
                        var key = req.Path == "/" ? "index.html" : req.Path.TrimStart('/').Replace('/', '.');
                        if (_resources.TryGetValue(key, out var data))
                        {
                            var    ext  = Path.GetExtension(key).Substring(1);
                            string mime = null;
                            if (ext == null || !Mime.TryGetValue(ext, out mime))
                            {
                                mime = "application/octet-stream";
                            }
                            await req.RespondAsync(200, data, mime);
                        }
                        else
                        {
                            await req.RespondAsync(404, NotFound, "text/plain");
                        }
                    }
                    else
                    {
                        var socket = await req.AcceptWebSocket();

                        SocketReceiveWorker(socket);
                        lock (_lock)
                        {
                            _pendingSocket?.Dispose();
                            _pendingSocket = socket;
                        }
                    }
                }
            }
        }