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.IO;
using System.Threading;
using System.Collections;
namespace WindowsFormsApplication15
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); } private void button1_Click(object sender, EventArgs e)
{ this.textBox1.Text += "开始";
test(); } public void test()
{ f2 h2 = new f2("andy", "hello"); Thread[] px = new Thread[10]; for (int i = 0; i < px.Length; i++)
{ px[i] = new Thread(h2.test);
px[i].Start(); } }
public class f2
{
string str1;
string str2;
public f2(string str1, string str2)
{ this.str1 = str1;
this.str2 = str2;
} public void test()
{ MessageBox.Show(str1 + ":" + str2); // TextBox1.Text += str1 + ":" + str2; //如何把messagebox.Show的输出方式换成这行呢?
}
} }
}================================================
需要把上面多线程的messagebox用textbox1.text来显示,即用十个线程向textbox1.text添加十次 adny:hello
网上好多委托的例子,可都不太完整,不会用呀,折腾半天还不行,哪位网友帮忙添加下委托,谢谢大家热心帮忙了!
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.IO;
using System.Threading;
using System.Collections;
namespace WindowsFormsApplication15
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); } private void button1_Click(object sender, EventArgs e)
{ this.textBox1.Text += "开始";
test(); } public void test()
{ f2 h2 = new f2("andy", "hello"); Thread[] px = new Thread[10]; for (int i = 0; i < px.Length; i++)
{ px[i] = new Thread(h2.test);
px[i].Start(); } }
public class f2
{
string str1;
string str2;
public f2(string str1, string str2)
{ this.str1 = str1;
this.str2 = str2;
} public void test()
{ MessageBox.Show(str1 + ":" + str2); // TextBox1.Text += str1 + ":" + str2; //如何把messagebox.Show的输出方式换成这行呢?
}
} }
}================================================
需要把上面多线程的messagebox用textbox1.text来显示,即用十个线程向textbox1.text添加十次 adny:hello
网上好多委托的例子,可都不太完整,不会用呀,折腾半天还不行,哪位网友帮忙添加下委托,谢谢大家热心帮忙了!
h2.m_TextBox = textBox1;
System.Threading.Thread[] px = new System.Threading.Thread[10]; for (int i = 0; i < px.Length; i++)
{ px[i] = new System.Threading.Thread(h2.test);
px[i].Start(); }
public class f2
{
string str1;
string str2; public TextBox m_TextBox;
public f2(string str1, string str2)
{ this.str1 = str1;
this.str2 = str2;
}
public void test()
{ m_TextBox.Invoke((MethodInvoker)delegate { m_TextBox.Text += str1 + ":" + str2; });
//MessageBox.Show(str1 + ":" + str2); }
} 这样看看.
线程里操作界面也可以不用委托的嘛!