visual studio 2005, C#, 多线程,调试问题

guostong 2007-11-26 10:59:47
用visual studio 2005做了一个C#的多线程程序,调试的时候,如果断点在主线程,没有问题,但如果断点设在线程里面,运行到断点时,visual studio 会停止反应,大概10秒以后才会恢复,但按下“F10”以后,程序根本就不断,直到程序第二次到达断点,才正常。

请问有没有解决的办法?
谢谢
...全文
322 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yhy0611 2007-12-01
  • 打赏
  • 举报
回复
我都是用写LOG
conan19771130 2007-12-01
  • 打赏
  • 举报
回复
up
guostong 2007-12-01
  • 打赏
  • 举报
回复
我的代码:

private void button_copy_Click(object sender, EventArgs e)
{
...
CCopyParam pCopy = new CCopyParam(m_strSourceFile, m_strDestFile, 0, 0);
Thread tCheck = new Thread(new ParameterizedThreadStart(ThreadCheckFile));
tCheck.Start(pCopy);
...
}

public void ThreadCopyFile(Object pCopy)
{
...
CallBackMessage(2, 0, iStart, iSize);
...
}

public delegate void delegateReturn(int iThread, int iRtn, long iStart, long iSize);

private void CallBackMessage(int iThread, int iRtn, long iStart, long iSize)
{
delegateReturn dReturn = new delegateReturn(MainDispatchMessage);
Object[] oParam = new Object[4];
oParam[0] = (Object)iThread;
oParam[1] = (Object)iRtn;
oParam[2] = (Object)iStart;
oParam[3] = (Object)iSize;
Invoke(dReturn, oParam);
}

private void MainDispatchMessage(int iThread, int iRtn, long iStart, long iSize)
{
...
switch (iRtn)
{
case 1: ...
// 断点在这里
...
}
...
}
far_2 2007-12-01
  • 打赏
  • 举报
回复
同意楼上~写LOG!!
jetxia 2007-11-28
  • 打赏
  • 举报
回复
我使用vs2005没有遇到过这样的问题。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace MultiThreads
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
Thread t = new Thread(Test);

t.Start();
MessageBox.Show("Main thread");
}


private void Test()
{
string tmp = "Background thread";

MessageBox.Show(tmp);

}

}
}
commandos 2007-11-28
  • 打赏
  • 举报
回复
多线程调试起来比较的麻烦。设置断点不是个好办法。你可以尝试在控制台上输出。或者写log 文件。。

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧