title: Very Simple Chat Program - Updating Chat Log?
body: <p>I have made a very simple chat program. All it does is saves the message as a new line in a txt file and displays that txt file in a richtextbox. The issue I am having is the user has to click "Update" to update the chat log. I wrote a loop that would check every second to see if there was a new message, however this locks up the form and if the user wants to send a message during that time, they would need to kill the form.</p>
  
  <p>Is this in anyway possible? Either auto updating the chat log when a new line is added to the txt document or even a regular interval?</p>
  
  <p>Currently what I am using is this:</p>
  
  <pre><code>$i = 1
  While ($i -eq 1)
  {
      sleep -Seconds 1
      $BEFORE = $richtextbox1.Text
  
      $CHATLOG = "\\NetworkShareEveryoneHasAccess\Chat.txt"
      $TOOUTPUT = Get-Content $CHATLOG | Out-String
      $richtextbox1.Text = $TOOUTPUT
  
      $AFTER = $richtextbox1.Text
  
      if ($BEFORE -ne $AFTER)
      {
          $i = 0
          $richtextbox2.Enabled = $true
          $richtextbox2.SelectionStart = $richtextbox2.TextLength;
          $richtextbox2.ScrollToCaret()
          $richtextbox2.Focus()
      }
  }
  </code></pre>
  
  <p>Again, the problem with this is that is freezes the form while it is checking to see if a new message (new line in the txt file).</p>
  
  <p>With my limited knowledge of PowerShell, I want to say this is not possible, but as I said my PowerShell knowledge is limited.</p>