我有一个正在线程池中执行的委托。计数作为变量正确传入,但是,当程序返回输出时,传入的初始值现在是更新版本。如何修改 ths 以使变量保持正确的值?
private void SetControlText(TextBox TB, string txt)
{
if (TB.InvokeRequired)
{
Invoke((MethodInvoker)delegate
{
TB.AppendText(txt + "\n");
TB.Update();
});
return;
}
TB.Text = txt;
}
private void DoWork(OCAdapter.OCAdapter Adapter, OutputForm output, int c, object ThreadContext = null)
{
int count = c;
//output.AppendToOutput("Initializing Adapter: " + count + " Test\n");
SetControlText(output.OutputBx, "Initializing Adapter: " + count + " Test\n");
try
{
var Test = Adapter.GetBookmarks();
if (Test != null)
//output.AppendToOutput("Adapter: " + count + " is valid\n");
SetControlText(output.OutputBx, "Adapter: " + count + " is valid\n");
}
catch (Exception ex)
{
//output.AppendToOutput("Exception occured on adapter: " + count + " Exception: " + ex.Message);
SetControlText(output.OutputBx, "Exception occured on adapter: " + count + " Exception: " + ex.Message);
}
}