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 摇奖机2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
bool b = false;
Thread th;
private void button1_Click(object sender, EventArgs e)
{
if (b == false)
{
b = true;
button1.Text = "暂停";
Thread ts = new Thread(playgame);
ts.IsBackground = true;
ts.Start();
}
else
{
b = false;
button1.Text = "开始";
}
Thread th = new Thread(playgame);
th.IsBackground = true;
th.Start();
// 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 Form2_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;//取消跨线程的限制
}
}
}
C# 摇奖机
于 2019-04-09 08:24:43 首次发布