zoukankan      html  css  js  c++  java
  • c#之线程随机

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

      

  • 相关阅读:
    linux下的进程
    进程间通讯
    const关键字
    关于嵌入式web服务器
    指针
    内存管理(malloc和free的用法)
    关于read和fread
    C库的制作
    C语言考试
    docker 配置阿里云镜像加速
  • 原文地址:https://www.cnblogs.com/mengluo/p/5579967.html
Copyright © 2011-2022 走看看