您的位置:首页 > 移动开发 > 微信开发

C#/.net学习-13-一个多线程的摇奖winform小程序

2017-02-09 09:52 246 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _05_摇奖机应用程序
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
bool b = false;
private void button1_Click(object sender, EventArgs e)
{
if (b == false)
{
b = true;
button1.Text = "停止";
Thread th = new Thread(PlayGame);
th.IsBackground = true;
th.Name = "新线程";
// th.
th.Start();
}
else//b==true
{
b = false;
button1.Text = "开始";
}
//PlayGame();
}
private void PlayGame()
{
Random r = new Random();
while (b)
{
label1.Text = r.Next(0, 10).ToString();
label2.Text = r.Next(0, 10).ToString();
label3.Text = r.Next(0, 10).ToString();
}
}

private void Form1_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐