Is there a way I can inline the delegated task instead of separating it on another function?
Original Code:
private void ofdAttachment_FileOk(object sender, CancelEventArgs e)
{
System.Threading.ThreadPool.QueueUserWorkItem((o) => Attach());
}
void Attach() // I want to inline this function on FileOk event
{
if (this.InvokeRequired)
{
this.Invoke(new Action(Attach));
}
else
{
// attaching routine here
}
}
I wanted it to be like this(no need to create a separate function):
private void ofdAttachment_FileOk(object sender, CancelEventArgs e)
{
Action attach = delegate
{
if (this.InvokeRequired)
{
// but it has compilation here
// "Use of unassigned local variable 'attach'"
this.Invoke(new Action(attach));
}
else
{
// attaching routine here
}
};
System.Threading.ThreadPool.QueueUserWorkItem((o) => attach());
}