title: How can I show a messagebox or loadingbox while doing a loop? (Code may be blocked and after 25 seconds continue)
body: <p>I already have this but it doesn't work... I need to check if a bit from plc is high or not. If it is still high I need to wait 5 seconds and check again.. Now I am trying to find something so there is some visual feedback for the user. In a textbox I want to put 'waiting...' while the points after waiting increase per 5 seconds. I tried a lot of things but can't seem to get it to work. Mostly of the time's it just hangs 25 seconds without updating the GUI and then it continues... :/</p>
  
  <pre><code>// First check if the plc bit, that says if there is still an order active, 
  // is still set. If so then we wait a couple seconds.
  var bitorder = Main.PIOGetValue(jbmis.IO_GET_INPUT, "BoxManInStarted");
  int counter = 1;
  string loadingpoints = "";
  
  loadtimer.Tick += timer_Tick;
  loadtimer.Interval = (int)TimeSpan.FromSeconds(5).TotalMilliseconds;
  loadtimer.Start();
  loadtimer.Enabled = true;
  
  // Stopwatch sw = new Stopwatch();
  
  while(bitorder != 0 &amp;&amp; loadtimercounter != 25)
  {
      // TODO multithreaded
  
      #region testcode
      // MessageBox.Show("Waiting for previous order to be stopped" + loadingpoints);
      // Context.UserMessageService
      //     .ShowMessage("Waiting for previous order to be stopped" + 
      //                  loadingpoints, "Waitingfororder");
      // sw.Start();
  
      // while (sw.Elapsed &lt; TimeSpan.FromSeconds(25)) 
      // {
      //     if (sw.Elapsed.Seconds % 5 == 0)
      //     {
      //         loadingpoints = loadingpoints + ".";
      //         tbScannedEANPick.Background = Brushes.OrangeRed;
      //         tbScannedEANPick.Text = "Waiting" + loadingpoints;
      //     }                                        
      // }
  
      // sw.Stop();
      // loadingpoints = loadingpoints + ".";
      // tbScannedEANPick.Background = Brushes.OrangeRed;
      // tbScannedEANPick.Text = "Waiting" + loadingpoints;
      // tbScannedEANPick.UpdateLayout();
      #endregion
  
      if (loadtimercounter % 5 == 0)
      {
          loadingpoints = loadingpoints + ".";
          tbScannedEANPick.Background = Brushes.OrangeRed;
          tbScannedEANPick.Text = "Waiting" + loadingpoints;
          tbScannedEANPick.IsReadOnly = true;
  
          bitorder = Main.PIOGetValue(jbmis.IO_GET_INPUT, "BoxManInStarted");
      }
  
      counter ++;
  }
  
  //  After 25 seconds stop timer and continue
  loadtimer.Stop();
  
  void timer_Tick(object sender, EventArgs e)
  {
      loadtimercounter += 5;
  }
  </code></pre>
  
  <p>I am searching for half a day... I tried to use Thread.sleep, timer, stopwatch, ... all in main thread or side thread.. </p>
  
  <p>Thanks in advance!!</p>