日期:2014-05-18 浏览次数:20694 次
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading; namespace bar4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private delegate int myde(int a); private void button1_Click(object sender, EventArgs e) { myde my = new myde(mymethod); textBox1.Text= my(1000).ToString(); } private int mymethod(int s) { Thread.Sleep(10000); return s * s; } private void button2_Click(object sender, EventArgs e) { myde my = new myde(mymethod); IAsyncResult async=my.BeginInvoke(5,null,null); int result = my.EndInvoke(async); textBox1.Text = result.ToString(); //this.Invoke(my, new Object[] { 1000 }); } } }
Thread _threadShow = new Thread(); if(_threadShow != null && _threadShow.ThreadState == ThreadState.Running) { return; } _threadShow = new Thread(new ThreadStart(mymethod)); _threadShow.Start();