title: Display consistently changing value on an ASP.NET web form
body: <p>I am currently writing a program in C# that constantly outputs random values between 1 and 12 and displays them in a label control on an ASP.NET web form. While the output is successfully written to the web form, it only displays one value. In other words, I want the label output to track the output (display) each value that is produced by the function as written below to produce a consistently changing value:</p>
  
  <pre><code>[WebMethod]
      public static string StreamData()
          {
              string[] value = new string[1]; 
  
              Random rnd = new Random();
  
              Thread t = new Thread(delegate ()
              {
                  while (true)
                  {
                      value[0] = rnd.Next(1, 13) + "";
                  }
              });
              t.Start();
  
  
              return value[0]; 
  
          }
  </code></pre>
  
  <p>I have tried using an AJAX function to pull the data from the function but I am not too sure if I am going about displaying the data in the right way: </p>
  
  <pre><code>     &lt;script type="text/javascript"&gt;
      $(function () {
          $.ajax({
              type: 'POST',
              url: 'default.aspx/streamdata',
              data: '',
              contentType: 'application/json; charset=utf-8',
              dataType: 'json',
              success: function (msg) {
                  //alert(msg.d);
                  $('#&lt;%= lblReading.ClientID %&gt;').html(msg.d);
              }
          });
               });
  &lt;/script&gt;
  </code></pre>
  
  <p>The program is being written to test the concept of trending live data from PLCs using TIA Portal 15 with said data obtained from sensor readings across a production line. The idea behind this program is to serve as a proof of concept that real-time data can in fact be displayed and trended in an ASP.NET web environment to be accessed across a range of web-compliant devices. Despite my efforts in displaying random values in this way, my attempts have been thus far unsuccessful, although I am determined to not give up. I researched this method which uses SignalR to achieve something similar to my desired solution, though I am unsure of how to implement it in my case: <a href="https://stackoverflow.com/questions/25829343/how-to-implement-real-time-data-for-a-web-page">How to implement real time data for a web page</a></p>
  
  <p>Could somebody please shed some light on how the above might be achieved?</p>
  
  <p>Many Thanks,</p>
  
  <p>Ben. </p>