【发布时间】:2017-06-11 19:33:44
【问题描述】:
Winforms、C#、VS2010。
我有一个在我的应用程序生命周期内运行的轮询线程。
有时它会在我的主窗体上调用一个事件。多年来我没有接触过代码,它运行成功,但现在我需要在参数列表中添加一个“out”参数。我在网上搜索过,但我发现的所有线程都与反射有关,并且尝试转换为我的上下文很复杂。我的不使用反射。
有人可以帮忙解决这个问题吗?在我读到的反射线程上,人们似乎检查了一些对象数组的输出参数结果,我没有在我的代码中使用它,而且我也不知道从哪里得到它。
private bool OnNeedUpdateCreateEvent(string title, string message,
bool creatingNew, out string newPlanName)
{
newPlanName = "";
// 1st pass through this function.
// Check to see if this is being called from another thread rather
// than the main thread. If so then invoke is required
if (InvokeRequired)
{
// Invoke and recall this method.
return (bool)Invoke(new onNeedToUpdatePlanEvent(OnNeedUpdateCreateEvent),
title, message, creatingNew, out newPlanName); <- wrong out param
}
else
{
// 2nd pass through this function due to invoke, or invoke not required
return InputDlg(this, title, message, creatingNew, out newPlanName);
}
}
【问题讨论】:
标签: c# multithreading winforms controls invoke