码迷,mamicode.com
首页 > 编程语言 > 详细

c#之线程随机

时间:2016-06-13 13:25:15      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

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;
            }
        }
    }
}

  

c#之线程随机

标签:

原文地址:http://www.cnblogs.com/mengluo/p/5579967.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!