【问题标题】:How to find where the exception was thrown inside a BackgroundWorker thread?如何找到异常在 BackgroundWorker 线程中引发的位置?
【发布时间】:2015-01-20 12:17:46
【问题描述】:

好的,这应该是基本的,但我找不到好的答案。 我只想在 BackgroundWorker 内抛出的异常中进行 VS 中断。 代码示例:

    private void btnBGWorker_Click(object sender, EventArgs e)
    {
        BackgroundWorker bgWorker = new BackgroundWorker();
        bgWorker.DoWork += bgWorker_DoWork;
        bgWorker.RunWorkerCompleted += bgWorker_RunWorkerCompleted;
        bgWorker.RunWorkerAsync();
    }

    void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        //I know e.Error have the Exception but
        if (e.Error != null)
            throw e.Error; //Well this does not work, VS will throw TargetInvocationException
    }

    void bgWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        //** How can I make VS break here !!!??? **
        throw new NotImplementedException();
    }

【问题讨论】:

    标签: c# exception backgroundworker


    【解决方案1】:

    您可以转到“调试”>“异常”菜单,然后确保在“公共语言运行时异常”旁边的“抛出”列中有一个复选标记。这将使 Visual Studio 中断所有异常从您的 CLR 代码中抛出。

    【讨论】:

      猜你喜欢
      • 2014-04-09
      • 1970-01-01
      • 2019-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多