Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#线程动画(闪电)_C#_Multithreading_Animation - Fatal编程技术网

C#线程动画(闪电)

C#线程动画(闪电),c#,multithreading,animation,C#,Multithreading,Animation,我想为使用线程的Windows窗体应用程序创建闪电。屏幕应该像闪电(DC漫画超级英雄)身体上的闪电一样运行。到现在为止,我的身体里有线条在画和消失。我为此使用了一个线程,因为我将不得不添加更多的动画与此闪电边 public void Animate() { Point xy1; Point xy2; Random rand=new Random(); for (int ctr = 1; ctr < 110; c

我想为使用线程的Windows窗体应用程序创建闪电。屏幕应该像闪电(DC漫画超级英雄)身体上的闪电一样运行。到现在为止,我的身体里有线条在画和消失。我为此使用了一个线程,因为我将不得不添加更多的动画与此闪电边

   public void Animate()
    {
        Point xy1;
        Point xy2;
        Random rand=new Random();

        for (int ctr = 1; ctr < 110; ctr++)
        {
            xy1 = new Point(rand.Next(0, this.Width),rand.Next(0, this.Height));
            xy2 = new Point(rand.Next(0, this.Width),rand.Next(0, this.Height));
            CreateGraphics().DrawLine(new Pen(Brushes.Yellow, 1),xy1,xy2);
            Thread.Sleep(100);
            this.Invalidate();



        }


    }
public void Animate()
{
xy1点;
xy2点;
Random rand=新的Random();
对于(int ctr=1;ctr<110;ctr++)
{
xy1=新点(rand.Next(0,this.Width),rand.Next(0,this.Height));
xy2=新点(rand.Next(0,this.Width),rand.Next(0,this.Height));
CreateGraphics().抽绳(新笔(画笔.黄色,1),xy1,xy2);
睡眠(100);
这个。使无效();
}
}

那么问题是什么?您的代码可能会因为尝试从后台线程绘制而被破坏。或者因为
冻结
UI线程。