您的位置:首页 > 编程语言 > C#

c#之线程随机

2016-06-13 11:10 489 查看
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;
using System.Threading;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
}
bool a;
public void playGame()
{
Random rd = new Random();

while (a)
{
this.label1.Text = rd.Next(0, 10).ToString();
this.label2.Text = rd.Next(0, 10).ToString();
this.label3.Text = rd.Next(0, 10).ToString();
}

}

private void button1_Click(object sender, EventArgs e)
{
if (!a)
{
a=true;
this.button1.Text = "暂停";
Thread th = new Thread(playGame);
th.IsBackground = true;
th.Start();
}
else {

this.button1.Text = "开始";
a = false;
}
}
}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: