首页 > 学院 > 开发设计 > 正文

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

2019-11-09 19:51:04
字体:
来源:转载
供稿:网友
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;        }    }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表