如何将带参数的函数委托给 C# 中的其他线程?
如果我自己尝试,我会收到此错误:
error CS0149: Method name expected
这就是我现在所拥有的:
delegate void BarUpdateDelegate();
private void UpdateBar(int Value,int Maximum,ProgressBar Bar)
{
if (Bar.InvokeRequired)
{
BarUpdateDelegate Delegation = new BarUpdateDelegate(Value, Maximum, Bar); //error CS0149: Method name expected
Bar.Invoke(Delegation);
return;
}
else
{
Bar.Maximum = Maximum;
Bar.Value = Value;
//Insert the percentage
int Percent = (int)(((double)Value / (double)Bar.Maximum) * 100);
Bar.CreateGraphics().DrawString(Percent.ToString() + "%", new Font("Arial", (float)8.25, FontStyle.Regular), Brushes.Black, new PointF(Bar.Width / 2 - 10, Bar.Height / 2 - 7));
return;
}
}
我想从另一个线程更新主线程中的进度条。