110,567
社区成员
发帖
与我相关
我的任务
分享
Thread TRec;
private void DataRecording_Load(object sender, EventArgs e)
{
TRec = new Thread (recording );
TRec.IsBackground = true;
TRec.Start(textBox1.Text );
}
bool flag = true;
//委托
private delegate void rec(string s);
private void recording()
{
if (InvokeRequired)
{
Invoke(new rec(Msg ));
}
else
{
if (mainys.alive == true)
{
while (flag)
{
for (int i = 0; i < mainys.ArrStrMsgID.Count; i++)
{
Msg(mainys.ArrStrMsgID[i].ToString() + "收到了" + mainys.Arrnum[i] + "个文件,接收时间为:");
foreach (object a in mainys.ArrRec)
{
string id = a.ToString().Substring(0, 5);
if (id == mainys.ArrStrMsgID[i].ToString())
{
Msg(" " + a.ToString().Substring(5));
}
}
}
Thread.Sleep(50);
textBox1.Clear();
}
}
else if (main.alive == true)
{
main m = new main();
}
TRec.Abort();
}
}
private void Msg(string s)
{
textBox1.AppendText(s);
textBox1.AppendText("\r\n");
}
private void button1_Click(object sender, EventArgs e)
{
flag = false;
TRec.Abort();
this.Close();
}
private delegate void rec(string s);
private void recordingText(string text)
{
if (textBox1.InvokeRequired)
{
Invoke(new rec(recordingText), new object[] { text });
}
else
{
Msg(text);
}
}
private void recording()
{
while (flag)
{
for (int i = 0; i < mainys.ArrStrMsgID.Count; i++)
{
recordingText(mainys.ArrStrMsgID[i].ToString() + "收到了" + mainys.Arrnum[i] + "个文件,接收时间为:");
foreach (object a in mainys.ArrRec)
{
string id = a.ToString().Substring(0, 5);
if (id == mainys.ArrStrMsgID[i].ToString())
{
recordingText(" " + a.ToString().Substring(5));
}
}
}
Thread.Sleep(50);
}
}
private void Msg(string s)
{
textBox1.AppendText(s);
textBox1.AppendText("\r\n");
}
Invoke(new rec(Msg),new object[]{textBox1.Text});
if (!string.IsNullOrEmpty(data))
{
textBox1.AppendText(data);
}
else
{
textBox1.Text="";
}
TRec.Start(textBox1.Text );//这样能行?
Invoke(new rec(Msg)); //传递了方法引用,为什么不传递参数?