多线程

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public delegate void game(string name);
        private void Form1_Load(object sender, EventArgs e)
        {
            game g = new game(test);
            this.Invoke(g, new object[] { "long" });
            gobanghadler += new gobang(Form1_gobanghadler);

            Thread[] ths = new Thread[3];
            for (int i = 0; i < 3; i++)
            {
              
                ths[i] = new Thread(new ThreadStart(delegate { MessageBox.Show(i.ToString()); }));
                ths[i].Name = i.ToString();
                ths[i].Start();
            }
        }
        public void test(string name)
        {
            MessageBox.Show(name);
        }
        void Form1_gobanghadler(string name)
        {
            throw new NotImplementedException();
        }
        public delegate void gobang(string name);
        public event gobang gobanghadler;

    }
}

posted @ 2012-12-04 20:56  蓝亭赏月  阅读(140)  评论(0编辑  收藏  举报