/// <summary> /// Constructor /// </summary> /// <param name="myPort">Port on wich the proxy listen</param> /// <param name="myMonitor">The form, which contains the pseudo console</param> public PortResourceProxy(int myPort, PortResourceProxyMonitor myMonitor) { _Monitor = myMonitor; _Port = myPort; PATH = System.Windows.Forms.Application.StartupPath + PATH; LoadMap(); _CancelToken = new CancellationTokenSource(); _WorkerThread = new Thread(new ThreadStart(WorkingThread)); _MyListener = new HttpListener(); _MyListener.Prefixes.Add("http://*:" + myPort.ToString() + "/"); _MyListener.Start(); _WorkerThread.Start(); }
/// <summary> /// There are correctly some problems 'bout disposing the HttpListener /// Stopping the worker thread /// </summary> private void Stop() { _Monitor = null; if (_MyListener != null) { _MyListener.Abort(); ((IDisposable)_MyListener).Dispose(); } _CancelToken.Cancel(); if (_WorkerThread != null) { _WorkerThread.Join(); if (_WorkerThread.IsAlive) { _WorkerThread.Abort(); } } }