StopWatch to Show Counter of Elapsed Time?

混江龙づ霸主 提交于 2020-04-22 02:54:41

问题


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();
  }
}

回答1:


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.



来源:https://stackoverflow.com/questions/29318267/stopwatch-to-show-counter-of-elapsed-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!