C#Form Get Action不间断完成 [英] C# Form Get Action done nonstop

查看:138
本文介绍了C#Form Get Action不间断完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何一次又一次地执行某些操作而不会发生诸如mousemove之类的事情,例如,我想创建随机数,直到我关闭程序.


当我尝试放置while(true)时,程序无法启动,我只是想通过随机数更改图片位置,并且我想这样做,直到程序close

I would like to know how I can do some action again and again without something to happen like mousemove for example i want to create random numbers till i close the program.


When I''m trying to put the while(true) the program cannot be started i just want to change picture location by random numbers and i want to do this until the program close

推荐答案

创建一个线程,该线程将为您生成随机数....因此,不会阻塞您的UI.从表单退出时中止线程.
或者,如果您想及时生成随机数,请使用计时器事件...
Create a thread which will generate random number for you .... so your UI will not be blocked. abort the thread when exiting from the form.
Or use a timer event if you want to generate the Random number in timely fashion...


while (true)
{
    //some code here
}



那是一个无限循环



让我对此进行详细说明....如果这是Winforms应用程序,并且在UI线程上执行此操作,则将阻止UI.在后台线程上执行或使循环在某个点退出

如果循环满足某些条件,可以使用break;语句强制循环退出



That''s an infinite loop



Let me expand on that a bit....if this is a Winforms app and you execute this on the UI thread, you''ll block your UI. Either execute on a background thread or make the loop exit at some point

You can force the loop to exit by using a break; statement if the loop meets some condition


您可以为此操作提供loop命令....
做-可能是最好的方法....
You can give the loop command for this action....
Do-While can be the best method....


这篇关于C#Form Get Action不间断完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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