• 大小: 55KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-09
  • 语言: C#
  • 标签: C#  多线程  

资源简介

C# 多线程开发源码事例 WINFORM

资源截图

代码片段和文件信息

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 MultiThreadDemo
{
    public partial class formname : Form
    {
        public static int temp1;
        public static int temp2;
        Thread t1 = new Thread(new ThreadStart(showLable1));
        Thread t2 = new Thread(new ThreadStart(showLable2));
        public formname()
        {
            InitializeComponent();
        }

        public static void showLable1()
        {
            for (int i = 0; i < 8000; i++)
            {
                temp1 =i ;
                Thread.Sleep(250);
            }
        }
        public static void showLable2()
        {
            for (int i = 0; i < 8000; i++)
            {
                temp2 = i;
                Thread.Sleep(870);
            }
        }
        public   void showLable1str()
        {
            for (int i = 0; i < 8000; i++)
            {
                this.label1.Text = i.ToString ();
               
            }
            Application.DoEvents();
        }
        public   void showLable2str()
        {
            for (int i = 0; i < 8000; i++)
            {
                this.label2.Text = i.ToString ();
             
            }
            Application.DoEvents();
        }

        private void timer1_Tick(object sender EventArgs e)
        {
            this.label1.Text = temp1.ToString();
            this.label2.Text = temp2.ToString();
        }

        private void btn_start_Click(object sender EventArgs e)
        {//开始线程
            t1.Start();
            t2.Start();
            btn_start.Enabled = false;
        }

        private void btn_abort_Click(object sender EventArgs e)
        {//杀死线程
            try
            {
                if (t1.IsAlive)
                    t1.Abort();
                if (t2.IsAlive)
                    t2.Abort();
                btn_abort.Enabled = false;
                btn_resume.Enabled = false;
                btn_start.Enabled = false;//5-1-a-s-p-x
                btn_suspend.Enabled = false;
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message.ToString());
            }
        }

        private void btn_suspend_Click(object sender EventArgs e)
        {//挂起线程
            if (t1.ThreadState == ThreadState.WaitSleepJoin)
            {
                t1.Suspend();
                t2.Suspend();
                this.btn_suspend.Enabled = false;
                this.btn_resume.Enabled = true;
            }
        }

        private void btn_resume_Click(object sender EventArgs e)
        {//恢复线程
            if (t1.ThreadState == ThreadState.Suspended)
            {
                t1.Resume();
                t2.Resume();
        

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3735  2010-03-12 09:43  多线程源码MultiThreadDemo\51aspx源码必读.txt

     文件      11776  2013-07-23 16:45  多线程源码MultiThreadDemo\bin\Debug\MultiThreadDemo.exe

     文件      38400  2013-07-23 16:45  多线程源码MultiThreadDemo\bin\Debug\MultiThreadDemo.pdb

     文件      14328  2013-07-23 16:46  多线程源码MultiThreadDemo\bin\Debug\MultiThreadDemo.vshost.exe

     文件        490  2009-06-11 05:14  多线程源码MultiThreadDemo\bin\Debug\MultiThreadDemo.vshost.exe.manifest

     文件       3880  2013-07-23 16:45  多线程源码MultiThreadDemo\Form1.cs

     文件       7568  2013-07-23 16:40  多线程源码MultiThreadDemo\Form1.Designer.cs

     文件       6008  2013-07-23 16:40  多线程源码MultiThreadDemo\Form1.resx

     文件       4945  2007-07-18 09:38  多线程源码MultiThreadDemo\from.gif

     文件       3741  2009-09-29 20:01  多线程源码MultiThreadDemo\MultiThreadDemo.csproj

     文件        919  2010-03-12 09:48  多线程源码MultiThreadDemo\MultiThreadDemo.sln

    ..A..H.     15872  2013-07-23 17:33  多线程源码MultiThreadDemo\MultiThreadDemo.suo

     文件       2980  2013-07-23 16:46  多线程源码MultiThreadDemo\obj\Debug\MultiThreadDemo.csproj.FileListAbsolute.txt

     文件        847  2013-07-23 16:40  多线程源码MultiThreadDemo\obj\Debug\MultiThreadDemo.csproj.GenerateResource.Cache

     文件      11776  2013-07-23 16:45  多线程源码MultiThreadDemo\obj\Debug\MultiThreadDemo.exe

     文件        180  2013-07-23 16:40  多线程源码MultiThreadDemo\obj\Debug\MultiThreadDemo.formname.resources

     文件      38400  2013-07-23 16:45  多线程源码MultiThreadDemo\obj\Debug\MultiThreadDemo.pdb

     文件        180  2013-07-23 16:37  多线程源码MultiThreadDemo\obj\Debug\MultiThreadDemo.Properties.Resources.resources

     文件        530  2010-03-11 23:13  多线程源码MultiThreadDemo\Program.cs

     文件       1403  2010-03-11 23:18  多线程源码MultiThreadDemo\Properties\AssemblyInfo.cs

     文件       2880  2009-09-29 19:51  多线程源码MultiThreadDemo\Properties\Resources.Designer.cs

     文件       5612  2009-09-29 19:51  多线程源码MultiThreadDemo\Properties\Resources.resx

     文件       1100  2009-09-29 19:51  多线程源码MultiThreadDemo\Properties\Settings.Designer.cs

     文件        249  2009-09-29 19:51  多线程源码MultiThreadDemo\Properties\Settings.settings

     文件        125  2007-03-27 14:33  多线程源码MultiThreadDemo\最新Asp.Net源码下载.url

     文件       1980  2010-03-11 23:12  多线程源码MultiThreadDemo\说明.txt

     目录          0  2010-03-08 14:44  多线程源码MultiThreadDemo\obj\Debug\Refactor

     目录          0  2010-03-08 14:44  多线程源码MultiThreadDemo\obj\Debug\TempPE

     目录          0  2013-07-25 08:38  多线程源码MultiThreadDemo\bin\Debug

     目录          0  2013-07-25 08:38  多线程源码MultiThreadDemo\obj\Debug

............此处省略7个文件信息

评论

共有 条评论