如何停止循环(C#)
来源:百度知道 编辑:UC知道 时间:2024/05/29 20:40:38
你可以这样啊:
建立一个线程.让一切操作在那个线程中运行包括执行死循环.
主线程则随时调用那个线程的挂起方法.
Abort();
你要是单线程死循环操作控件的话那.........
程序假死是肯定的了.
但是用多线程操作控件,那么你就要在你那个窗体的加载时先为那个窗体对象的一个静态属性赋值:
Form1.CheckForIllegalCrossThreadCalls = false;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace dietest1
{
public partial class Form1 : Form
{
System.Threading.Thread threadToPlay;
public Form1()
{
InitializeComponent();
Form1.CheckForIllegalCrossThreadCalls = false;
}
void Go()
{
System.Threading.ThreadStart ts = new System.Threading.ThreadStart(die);
threadToPlay = new System.Threading.Thread(ts);
thre