到底怎么改这错啊,我是想在listBox里显示Thread运行的结果,帮帮忙啊~~~~~~
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System .Threading ;
namespace _1141
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
}


public int m_x=0;
public  void WriteThread()
{
Thread.Sleep (1000);
m_x=0;
}
public  void ReadThread10()
{
int a=10;
for(int y=0;y<5;y++)
{
string s="ReadThread10";
s=s+"#multiplier=";
s=s+Convert.ToString (a)+"#";
s=s+a*m_x;
listBox1.Items .Add (s);
Thread.Sleep (1000);
}
}
public void ReadThread20()
{
int a=20;
for(int y=0;y<5;y++)
{
string s="ReadThread20";
s=s+"#multiplier=";
s=s+Convert.ToString (a)+"#";
s=s+a*m_x;
listBox1.Items .Add (s);
Thread.Sleep (1000);
}
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
// 
// listBox1
// 
this.listBox1.Location = new System.Drawing.Point(16, 16);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(208, 212);
this.listBox1.TabIndex = 0;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
// 
// Form1
// 
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.listBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread] static void Main() 
{
Application.Run(new Form1());
Thread t0=new Thread (new ThreadStart (WriteThread));
Thread t1=new Thread (new ThreadStart (ReadThread10));
Thread t2=new Thread (new ThreadStart (ReadThread20));
t0.IsBackground =true;
t1.IsBackground =true;
t2.IsBackground =true;
t0.Start ();
t1.Start ();
t2.Start ();
} private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{

}
}
}
我将WriteThread,ReadThread10,ReadThread20改为静态的也不行。初始化Form1三个事例s1 s2 s3后用Thread t0=new Thread (new ThreadStart (s1.WriteThread));
Thread t1=new Thread (new ThreadStart (s2.ReadThread10));
Thread t2=new Thread (new ThreadStart (s3.ReadThread20));
这下可以运行了 但就是每显示结果。
怎么回事啊???