title: Expose console app info through web browser in .Net core 3.1
body: <p>I have a heavy console app that executes several threads that read, perform calculations and write to outputs in different scenarios. Now I'm triying to simply create a way for everyone to be able to access to the data (real-time or near-real-time) through a web browser using either localhost or http/https.</p>
  <p>I've tried following <a href="https://www.stevejgordon.co.uk/what-are-dotnet-worker-services" rel="nofollow noreferrer">this resource</a> as well as <a href="https://stackoverflow.com/questions/62707093/dotnet-core-3-1-console-app-hosting-optional-web-api-for-control">this other</a>. I've actually looked around and found about self  hosting, but I don't really know how to implement it in a simple manner.</p>
  <p>for brevity's sake, I add a very simple example of a console app:</p>
  <pre><code>using System;
  using System.Collections.Concurrent;
  using System.Threading;
  
  namespace ConsoleApp1
  {
      class Program
      {
          public static int x = 0;
          public static int y = 0;
          public static int z = 0;
          public static ConcurrentDictionary&lt;String, int&gt; ValuesDictionary = new ConcurrentDictionary&lt;string, int&gt;();
  
          static void Main(string[] args)
          {
              //Function that updates the values in the dictionary
              Thread createInputFileThread = new Thread(() =&gt; UpdateDictionaryThreadFunction(10000));
              createInputFileThread.Start();
  
              //How to start a simple web host here!
          }
  
          public static void UpdateDictionaryThreadFunction(int refreshTime)
          {
              while (true)
              {
                  Thread.Sleep(refreshTime);
                  if (x &lt; 100000 &amp;&amp; y &lt; 100000 &amp;&amp; z &lt; 100000)
                  {
                      ValuesDictionary.AddOrUpdate(&quot;ValueX&quot;, x, (key, oldValue) =&gt; oldValue + 1);
                      ValuesDictionary.AddOrUpdate(&quot;ValueY&quot;, y, (key, oldValue) =&gt; oldValue + 2);
                      ValuesDictionary.AddOrUpdate(&quot;ValueZ&quot;, z, (key, oldValue) =&gt; oldValue + 3);
                  }
                  else
                  {
                      ValuesDictionary.AddOrUpdate(&quot;ValueX&quot;, x, (key, oldValue) =&gt; 0);
                      ValuesDictionary.AddOrUpdate(&quot;ValueY&quot;, y, (key, oldValue) =&gt; 0);
                      ValuesDictionary.AddOrUpdate(&quot;ValueZ&quot;, z, (key, oldValue) =&gt; 0);
                  }
              }
          }
      }
  }
  </code></pre>
  <p>The goal here would be to access the data in the ValuesDictionary through something like <code>localhost:someport</code> or <code>http://somename:someport</code> and obtain something like: (The values would be refreshed every x seconds)</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: center;">Name</th>
  <th style="text-align: center;">Value</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: center;">ValueX</td>
  <td style="text-align: center;">34</td>
  </tr>
  <tr>
  <td style="text-align: center;">ValueY</td>
  <td style="text-align: center;">42</td>
  </tr>
  <tr>
  <td style="text-align: center;">ValueZ</td>
  <td style="text-align: center;">42</td>
  </tr>
  </tbody>
  </table>
  </div>