摇奖机

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 摇奖机
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }
        bool b = false;
        private void button1_Click(object sender, EventArgs e)
        {
            if(b==false)
            {
                b = true;
                Thread th = new Thread(PlayGame);
                th.IsBackground = false;
                th.Start();
                button1.Text = "暂停";
            }
            else
            {
                b = false;
            }
        }
        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;
        }
    }
}

 

posted @ 2021-08-22 19:48  静态类  阅读(116)  评论(0编辑  收藏  举报