title: Breaking from a loop with button click - C#
body: <p>I have a question regarding looping with button click event, I've tried many methods &amp; searched many pages in search for a simple answer for the past hour, but the truth is each answer just looks like alien code, probably because I'm still very new to developing.</p>
  
  <p>Here's a simplified version of what I'm trying to do : </p>
  
  <pre><code>private string Message = "Hello";
  
  private void Spam(bool loop)
  {
      if (loop == true)
      {
          while (loop == true)
          {
              MessageBox.Show(Message);
          }
      }
      else { MessageBox.Show("Spamming has stopped !! "); }
  }
  
  private void button1_Click(object sender, EventArgs e)
  {
      Spam(true);
  }
  private void button2_Click(object sender, EventArgs e)
  {
      Spam(false);
  }
  </code></pre>
  
  <p>Obviously this isn't my API, or it'd be a useless thing to invent, however, the code itself is long &amp; you guys always ask for "relevant code" (No disrespect), so there it is.</p>
  
  <p>My problem : Breaking out of the spam loop upon clicking button 2, the code to me looks decent enough for the API to figure out, but each time button 1 is clicked, the API freezes. </p>