每秒运行一次函数 Visual C# [英] Run function every second Visual C#

查看:43
本文介绍了每秒运行一次函数 Visual C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有计时器问题.我在函数中有函数(在函数中绘制)

I have problems with timer. I have function in function (draw in func)

void func(){

 /*...do something ... */
for(){
   for() {
  /*loop*/

 draw(A,B, Pen);

 }

/*... do something ...*/
  }
}

这是绘制函数

   public void draw1(Point Poc, Point Kra, Pen o) {
      Graphics g = this.CreateGraphics();
      g.DrawLine(o,Poc.X+4, Poc.Y+4,Kra.X+4, Kra.Y+4);
      g.Dispose();
      }

我在按钮点击时调用函数'func'

I call function 'func' on button click

private void button4_Click(object sender, EventArgs e){

    func();

}

我想每隔一秒调用一次绘制函数(每秒绘制一条线).在绘图之间,函数需要继续工作并计算=循环,并在一段时间(间隔)内绘制下一行.我试过

I want to call draw function evry second (draw the line every second). Between drawings, function needs to continue working and calculate = loop, and draw next line for some time(interval). I tried with

timer1.Tick += new EventHandler(timer1_Tick);

等等.

private void timer1_Tick(object sender, EventArgs e)
    {
        ...
        draw(A, B, Pen)
    }

等等.

但所有这些都会停止我的功能,并随机绘制一条线.我只想要函数func"中两个绘图之间的时间(间隔).没有计时器工作正常,但立即绘制所有线条,我需要缓慢绘制.干杯.

but all that stops my function, and draw one random line. I just want the time(interval) between two drawings in function 'func'. Without timer works fine, but draw all lines immediately, I need slow drawing. Cheers.

推荐答案

SOLVED for now with

SOLVED for now with

System.Threading.Thread.Sleep(700);

这篇关于每秒运行一次函数 Visual C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆