Example #1
0
        public void Listen()
        {
            try
            {
                var localIp = IPAddress.Parse(Server.ServerIp);
                Listener = new TcpListener(localIp, Port);
                Listener.Start();
            }
            catch (Exception e)
            {
                Server.WriteDisplay(e);
                Server.SetTextBtn(@"Start");
                Server.SetColorDisplay(Color.White);
                return;
            }

            while (IsActive)
            {
                try
                {
                    var s = Listener.AcceptTcpClient();
                    _processor = new HttpProcessor(s, this);
                    Thread = new Thread(_processor.Process);
                    Thread.Start();
                    Thread.Sleep(1);
                }
                catch (SocketException) // or whatever the exception is that you're getting
                {

                }
            }
        }
            public DispatcherWorkerThreadDetails(Thread thread)
            {
                this.Thread = thread;

                Dispatcher dispatcher;

                // Get the Dispatcher instance for the thread
                do
                {
                    dispatcher = Dispatcher.FromThread(thread);

                    // The dispatcher might not have been spun up yet so, if not, sleep and try again until it is
                    if (dispatcher == null)
                    {
                        Thread.Sleep(100);
                    }
                } while (dispatcher == null);

                // Hook the events that tell us when the Dispatcher is actually doing something
                DispatcherHooks dispatcherHooks = dispatcher.Hooks;
                dispatcherHooks.DispatcherInactive += (s, a) => this.HasWork = false;
                dispatcherHooks.OperationPosted += (s, a) => this.HasWork = true;
            }