您可以像这样使用e.Result: 第一步:您需要添加事件RunWorkerCompleted。
_bw.RunWorkerCompleted += BwRunWorkerCompleted;
并创建函数BwRunWorkerCompleted,这将在线程完成后触发。例如:
private void BwRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// First, handle the case where an exception was thrown.
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
}
//
if (e.Result != null)
{
// test if result is true or false <== HERE YOU GO!
if ((Boolean)e.Result == true)
{
this.Hide();
Form fm = new SFGrilla(ref lr, ref binding);
fm.ShowDialog();
this.Close();
}
}
else
{
// hide the progress bar when the long running process finishes
progressBar.Visible = false;
// enable button
btnLogin.Enabled = true;
}
}
你的 testbool() 应该有正确的参数:
private void testbool(object sender, DoWorkEventArgs doWorkEventArgs) {
success = true;
doWorkEventArgs.Result = success;
}
希望能帮助到你。