关于另一个线程调用另一个线程控键的问题
using System;--------------------编程问答-------------------- this.l.Invoke(new DAdd(add));//------------帮忙解释下这句什么意思
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
class Class1
{
private Panel l;
private Label la;
public Class1(Panel a)
{
}
delegate void DAdd();//委托一 个方法
public void add()
{
if (this.l.InvokeRequired)//-----同下
{
this.l.Invoke(new DAdd(add));//------------帮忙解释下这句什么意思
}
else
{
int x = 0, y = 25;
Label la = new Label();
Random rand = new Random();
int r = rand.Next(97, 123);
la.Text = ((char)r).ToString();
this.l.Controls.Add(la);
la.Location = new Point(x, y);
}
}
}
}
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 WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Class1 cc = new Class1(this.panel1);
new Thread(new ThreadStart(cc.add)).Start();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
}
}
}
异步委托,另开一线程,这线程属于线程池的
--------------------编程问答-------------------- 异步委托最好不要在主线程里, 大量操作会程序假死, 即异步委托会执行完函数才把权限交还给主线
补充:.NET技术 , C#