/// <summary> /// Function starts HttpListener. /// </summary> public async void StartAsync() { if (httpListener.IsListening) { return; } httpListener.Start(); PowerHelper.ForceSystemAwake(); while (httpListener.IsListening) { try { HttpListenerContext context = await httpListener.GetContextAsync(); await Task.Run(() => ProcessRequestAsync(context)); } catch (HttpListenerException) { break; } catch (Exception e) { // Unexepected error occured Debug.WriteLine(e.Message); break; } } }
/// <summary> /// Function stops HttpListener /// </summary> public void Stop() { if (httpListener.IsListening) { httpListener.Stop(); PowerHelper.ResetSystemDefault(); } }