运行功能每秒的Visual C# [英] Run function every second Visual C#

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

问题描述

我有计时器的问题。
我在函数function(绘制FUNC)

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



etc..

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

但所有的停止我的功能,抓一张随机线。
我只想时间函数'功能'(间隔)两张图纸之间。如果不定时工作正常,但马上绘制所有行,我需要慢图纸。
干杯。

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.

推荐答案

解决了现在

System.Threading.Thread.Sleep(700);

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

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