我无法在作为后台线程运行的函数中设置断点。是否可以调试后台线程。
以下是实现:
// Thread settings
SettingTestThread1();
BackgroundWorker testThread1 ;
private void SettingTestThread1()
{
testThread1 = new BackgroundWorker();
testThread1.DoWork += new DoWorkEventHandler(testThread1Handler);
testThread1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(testThread1CompletedHandler);
thread.Sleep(50) ; testThread1 .WorkerReportsProgress = true;
}
private void testThread1Handler(object sender, DoWorkEventArgs e)
{
//body of the testThread
func1();
func2();
func3();
}
private void testThread1CompletedHandler(object sensor, RunWorkerCompletedEventArgs e)
{
//Clean up , destruct-or calling, disposing off variable
}
main()
{
SettingTestThread1();
testThread1.RunWorkerAsync();
}
但是当我运行它时,我无法看到断点击中任何 func1、2 或 3 主体。我也在代码中的 testThread1.RunWorkerAsync 之前在 main 中调用 SettingTestThread1()。
Rgds, Rp