我该如何调试呢? [英] How do I debug this?

查看:80
本文介绍了我该如何调试呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有一个用于ActiveX控件的项目(内置VS2k5 Pro,但如果需要的话,我也有2k10 Pro).

它包含一个对话框(CDialog),该对话框创建一个线程(CWinThread),该线程打开服务器的套接字(CAsyncSocket)以获取一些数据.

这样设计的目的是,当套接字完成对数据的检索后,它将通过Windows消息(PostThreadMessage)通知线程.

问题在于,一旦套接字被连接(调用Connect()方法),线程就似乎停止处理Windows消息.我通过从应用程序运行的各个点向线程发送消息(即它们不再在处理程序中接收到消息)来测试此消息(因此,我知道处理程序也已正确设置).

现在,这只是一个相当大的项目的一个组成部分,因此自然而然,我的第一反应就是将其隔离.我创建了一个示例ActiveX控件,该控件创建了一个对话框,该对话框创建了打开套接字的线程.在示例应用程序中,所有消息传递都可以正常工作.这意味着该集团内部的某个项目正在引起冲突,但是我能想到的找出冲突的唯一方法是开始在新的示例应用程序中从头开始重新构建项目,一次添加一个直到示例应用程序也崩溃.

OK, I''ve got a project (built in VS2k5 Pro but I also have 2k10 pro available if necessary) for an activeX control.

It contains a dialog (CDialog) that creates a thread (CWinThread) that opens a socket (CAsyncSocket) to a server to get some data.

It is designed such that when the socket has completed retrieving the data, it notifies the thread via a windows message (PostThreadMessage).

The problem is that as soon as the socket is connected (the Connect() method is called), the thread seems to stop processing windows messages. I tested this by sending messages to the thread from various points in the application''s run and that is when they stop getting recieved in the handler (so I know the handler is setup properly as well).

Now, this is only a single component of a fairly large project so naturally my first reaction was to isolate it. I created a sample ActiveX control which created the dialog that created the thread that opened the socket. All the messaging works fine in the sample app. This means that something within the conglomeration that the project is is causing a conflict but the only way I can think of to find out what is conflicting is to start re-building the project from scratch in the new sample app adding one piece at a time until the sample app also breaks.

Anyone have any better ideas on how to figure out what is causing the messaging to stop or thoughts on how you would debug this?

推荐答案

您是否正在检查所有内容的返回代码? ?特别是CAsyncSocket::Connect?

在所有可覆盖的通知功能中设置断点也是一个好主意.在OnConnect上放置跟踪.

如果您到达OnReceive,请尝试从那里开始.

您的描述在哪里细分有点含糊.但我想这是您问题的一部分.

嗯,只有几个主意.
Are you checking return codes for everything? Especially CAsyncSocket::Connect?

Setting breakpoints in all overridable notification functions is also a good idea. Put a trace in OnConnect.

If you reach OnReceive, try stepping from there.

Your description is a bit vague as to where it breaks down. But I suppose that''s part of your problem.

Ah well, just a few ideas.


检查线程的终止/挂起状态.

问题也变成了您在哪里使用套接字.是直接在线程中使用它,还是出于某种原因将其发回到Active X控件中.

代码是否正在检查SOCKET_ERROR并为WSA调用使用适当的get last错误?

我建议在生成的线程中发布主要功能的代码段.我怀疑错误的错误处理(导致错误的线程术语)是这里的根本原因.
Check your thread for terminated/suspended states.

Also the question becomes where are you using the socket. Is it being used in the thread directly or for some reason are you shipping it back up to the Active X control.

Is the code checking for SOCKET_ERROR and using the appropriate get last error for WSA calls?

I would suggest posting a snippet of the main function within your spawned thread. I suspect improper error handling(which leads to improper thread term) is the root cause here.


我认为您正在从线程中编辑项目的GUI.在这种情况下,您将必须小心.如果要从Windows窗体(或任何GUI组件)上的线程中发布任何状态更新,则必须省略该部分或仔细进行.

这是仔细进行操作的一种可能方法.启动线程时,将类型为Control的对象传递给该对象,并使该Control为您要从该线程中编辑的Control.现在,当您想要更改该控件的任何属性时,可以使用Control.Invoke()方法来更新Control中的任何属性.
您需要查看这些链接,
MSDN上的Control.Invoke方法: http://msdn.microsoft.com/en-us/library/zyzhdc6b .aspx [^ ]
C#中的MSDN上的代理: http://msdn.microsoft.com/zh-cn/library /ms173171(VS.80) [ ^ ]

如果您需要更多信息,请回复或发邮件给我或其他:)
I think that you are editing the project''s GUI from the thread. In such a case you will have to be careful. If you are posting any status updates from the thread on the windows form (or any GUI component), you will have to either omit that part or do it carefully.

Here is a possible way to do it carefully. When starting the thread, pass to it an object of type Control and let that Control be the Control you want to edit from the thread. Now, when you want to change any property for that control you can use the Control.Invoke() method to update any property in the Control.

You will need to look at those links,
MSDN on Control.Invoke method: http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx[^]
MSDN on Delegates in C#: http://msdn.microsoft.com/en-us/library/ms173171(VS.80)[^]

If you need more information, reply back or message me or whatever :)


这篇关于我该如何调试呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆