MainForm.
one textbox,one button.Following is the code: public partial class Form1 : Form
{
public delegate void WriteString(string str);
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Thread thread1 = new Thread(new ThreadStart(SafeMethod));
thread1.Start();
} private void SafeMethod()
{
this.WriteStringToTextBox("s");
} private void WriteStringToTextBox(string str)
{
if (this.textBox1.InvokeRequired)
{
WriteString ws = new WriteString(WriteStringToTextBox);
this.Invoke(ws, new object[] { str });
}
else
{
textBox1.AppendText(str);
}
}
}
But when I click the button,it shows only one "s" in the textbox.
Why it doesnot go on appending "s" to the textbox???
one textbox,one button.Following is the code: public partial class Form1 : Form
{
public delegate void WriteString(string str);
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Thread thread1 = new Thread(new ThreadStart(SafeMethod));
thread1.Start();
} private void SafeMethod()
{
this.WriteStringToTextBox("s");
} private void WriteStringToTextBox(string str)
{
if (this.textBox1.InvokeRequired)
{
WriteString ws = new WriteString(WriteStringToTextBox);
this.Invoke(ws, new object[] { str });
}
else
{
textBox1.AppendText(str);
}
}
}
But when I click the button,it shows only one "s" in the textbox.
Why it doesnot go on appending "s" to the textbox???
private void SafeMethod()
{
string[] strArray=new string[20];
for (int i = 0; i < strArray.Length; i++)
{
Thread.Sleep(1000);
this.WriteStringToTextBox("s");
}
}There is another button named pauseButton.When I press it,it paused to append text to the textbox.
So I donot want to use a fixed string Array.Any other way?
能连续输入sssss...
I see.but if i donot use the fixed-length array,it couldnot.