S
Sin Jeong-hun
I've been using delegates as class-wide variables, like:
class TheForm: Form
{
delegate void ChangeTextDelegate(string msg);
ChangeTextDelegate ctd;
public TheForm()
{
ctd=new ChangeTextDelegate(...)
}
void OnMessage(string msg)
{
if(InvokeRequired)
{
this.BeginInvoke(this.ctd,new object[]{msg});
}
else
{
TheTextBox.Text=msg;
}
}
But a few minutes ago I saw a sample code that used a delegate as a
local variable like:
class TheForm: Form
{
delegate void ChangeTextDelegate(string msg);
void OnMessage(string msg)
{
if(InvokeRequired)
{
ChangeTextDelegate ctd=new ChangeTextDelegate(...)
this.BeginInvoke(ctd,new object[]{msg});
}
else
{
TheTextBox.Text=msg;
}
}
Does this make any difference? If so, which is the correct way? Thank
you.
class TheForm: Form
{
delegate void ChangeTextDelegate(string msg);
ChangeTextDelegate ctd;
public TheForm()
{
ctd=new ChangeTextDelegate(...)
}
void OnMessage(string msg)
{
if(InvokeRequired)
{
this.BeginInvoke(this.ctd,new object[]{msg});
}
else
{
TheTextBox.Text=msg;
}
}
But a few minutes ago I saw a sample code that used a delegate as a
local variable like:
class TheForm: Form
{
delegate void ChangeTextDelegate(string msg);
void OnMessage(string msg)
{
if(InvokeRequired)
{
ChangeTextDelegate ctd=new ChangeTextDelegate(...)
this.BeginInvoke(ctd,new object[]{msg});
}
else
{
TheTextBox.Text=msg;
}
}
Does this make any difference? If so, which is the correct way? Thank
you.