title: In process web server in UWP app to receive JSON messages
body: <p>I have a question, I have been following this post:</p>
  
  <p><a href="https://sandervandevelde.wordpress.com/2016/04/08/building-a-windows-10-iot-core-background-webserver/" rel="nofollow noreferrer">IoT core background webserver</a></p>
  
  <p>to build my background webserver. However, this post along with most that I read are just a headless background service. In my case, I do have a main app with a UI as well that the user can view and interact with. So, I am not headless, I want the app to start and show the UI when the device starts up. But, I also want a web server running in the background at all times (from within the app) to listen for JSON messages to be posted. For example, if I have text on the UI that I want to change by sending a JSON message to the device/app. </p>
  
  <p>I understand that this is typically referred to as an in-process web server. So, I took most of the link above to implement the web server class and then from my MainPage.xaml.cs code behind, I did this to instantiate the web server class on another thread to listen for messages:</p>
  
  <pre><code>    private async void StartServer()
      {
          var webServer = new WebServer();
  
          await ThreadPool.RunAsync((workItem) =&gt;
          {
              webServer.Start();
          });
      }
  </code></pre>
  
  <p>Is this the right way to start the web server in a background thread? As I read the code (and be easy on me, as I am still learning all of this stuff), it seems that the web service will start in the thread pool but then stop after it receives one message. Is that right or will it continue to run indefinitely (or as long as the app is running)?</p>
  
  <p>Thanks!</p>