Big Pimpin
Big Pimpin

Reputation: 437

StopWatch to Show Counter of Elapsed Time?

I have a textbox on my windows form that I am wanting to show the elapsed time that my procedure has taken, but I am not seeing any time counting in the textbox. Below is my code

public partial class Form1 : System.Windows.Forms.Form
{
  private Stopwatch watch = new Stopwatch()l

  private void btn_RashadSL()
  {
    watch.Start();
    //lots of code here that typically takes around 15 - 20 minutes to complete
  }
  private void timer_Tick(object sender, EventArgs e)
  {
    textbox1.Text = watch.Elapsed.Seconds.ToString();
  }
}

Upvotes: 0

Views: 962

Answers (1)

Moo-Juice
Moo-Juice

Reputation: 38825

Given the code you have posted I'd say the problem is that at no point have you set up a timer to actually call the timer_Tick method.

Upvotes: 1

Related Questions