无法为正在Visual Studio 2012后台C#中运行的函数设置断点
我无法在作为后台线程运行的函数中设置断点。是否可以调试后台线程 实施情况如下:无法为正在Visual Studio 2012后台C#中运行的函数设置断点,c#,multithreading,visual-studio-2012,backgroundworker,C#,Multithreading,Visual Studio 2012,Backgroundworker,我无法在作为后台线程运行的函数中设置断点。是否可以调试后台线程 实施情况如下: // Thread settings SettingTestThread1(); BackgroundWorker testThread1 ; private void SettingTestThread1() { testThread1 = new BackgroundWorker(); testThread1.DoWork += new DoWorkEventHandler(testThread
// 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();
}
但是当我运行这个时,我看不到断点击中任何一个1,2或3体。
在代码中,我在testThread1.RunWorkerAsync之前的main中调用SettingTestThread1()
Rgds,
Rp我想这里发生的是,在调用后台线程之前,您的程序已经存在。 运行后台工作程序后,请尝试添加睡眠:
public static void main()
{
SettingTestThread1();
testThread1.RunWorkerAsync();
System.Threading.Thread.Sleep(2000);
}
事实上,后台线程的终止对于程序退出来说并不是强制性的。如果希望主线程等待后台线程结束。。。嗯,不要使用后台线程,而是使用普通线程。如果您抛出它,可能会有所帮助-。