Visual Studio 2010挂起时我调试方法AttachThreadInput() [英] Visual Studio 2010 hangs when I debug method AttachThreadInput()

查看:162
本文介绍了Visual Studio 2010挂起时我调试方法AttachThreadInput()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Visual Studio 2010 Ultimate SP1,我的项目是基于MFC。

I have Visual Studio 2010 Ultimate SP1 and my project is based on MFC.

当我调试我的项目的下一个代码Visual Studio is hangs:

When I debuging next code of my project Visual Studio is hangs:

CWnd* _window = CWnd::FromHandle(_hwnd_);
if (_window) {
    DWORD nForeThread, nAppThread;

    nForeThread = ::GetWindowThreadProcessId(::GetForegroundWindow(), 0);
    nAppThread = GetCurrentThreadId();

    if (nForeThread != nAppThread)
    {
        AttachThreadInput(nForeThread, nAppThread, TRUE);
        _window->BringWindowToTop();
        _window->ShowWindow(SW_RESTORE);
        AttachThreadInput(nForeThread, nAppThread, FALSE);
    }
    else
    {
        _window->BringWindowToTop();
        _window->ShowWindow(SW_RESTORE);
    }
}



我在下一行有一个断点: p>

I have a breakpoint on the next line:

    AttachThreadInput(nForeThread, nAppThread, TRUE);

因此,如果我按F10或F11或F5按钮,则VS立即挂起。

So if I push F10 or F11 or F5 button, then VS immediately hangs.

这可能是什么问题?

推荐答案

我怀疑你刚刚复制代码从某处没有理解的后果。这是 Win32程序员应该知道的五件事我在2005年讨论过。

I get the suspicion that you just copied this code from somewhere without understanding the consequences. This is one of the Five Things Every Win32 Programmer Should Know I discussed back in 2005.

AttachThreadInput 从这两个线程拿所有的钱,并把他们放在一个联合银行帐户,这样两个线程都不能提取任何钱,除非两个线程一起去银行提款。

AttachThreadInput means "Please take all the money from these two threads and put them in a joint bank account, so that neither thread can withdraw any money unless both threads go to the bank together to withdraw the money."

这是伟大的,如果两个线程已婚或同一家庭的成员或以其他方式互相信任共享银行帐户,也可以协调他们的行动,以便当他们中的一个需要钱,它可以调用其他一个人说嘿,你能和我一起来银行吗?我需要一些钱。

This is great if the two threads are married or members of the same family or otherwise trust each other with a shared bank account, and also can coordinate their actions so that when one of them needs money, it can call the other one and say "Hey, could you come to the bank with me? I need some money."

在你的情况下,你说:请把所有的钱和所有的钱从一个随机的人走在街上,并把它们放入一个联合银行帐户,所以我和那个人都不能提取任何钱,除非我们一起去银行

In your case, you said, "Please take all all my money and all the money from some random person walking down the street and put them into a joint bank account, so that neither I nor that other person can withdraw any money unless both of us go to the bank together to withdraw the money."

这是一个坏主意,无论对你还是对其他人,因为你现在不能提取任何钱,除非你设法联系另一个人。但是,因为你只是抓了一个随机的人走在街上,你不知道他的手机号码,所以你没有办法联系他说嘿,你能和我一起去银行吗?而随机的人现在可以访问您的所有银行帐户信息。 (和你的钱和那个人的钱聚在一起 - 这不是你的钱和那个人的钱了,只是一堆钱。)

This is a bad idea, both for you and for the other person, since you now cannot withdraw any money unless you manage to get in touch with the other person. But since you just grabbed a random person walking down the street, you don't know his cell phone number, so you have no way of contacting him to say "Hey, can you go down to the bank with me?" And that random person now has access to all your bank account information. (And your money and that other person's money got lumped together -- it's not "your money" and "that other person's money" any more. It's just one pile of money.)

将银行帐户更改为输入队列,将钱更改为输入,然后将转到银行更改为检查邮件队列。

Change "bank account" to "input queue", "money" to "input", and "go to the bank" to "check the message queue".

在你的情况下,你做的是抓住Visual Studio并说好吧,我们现在有一个联合银行帐户!现在看看会发生什么:Visual Studio不能提取任何钱,因为它需要你去银行。但是你不能去银行,因为你被打破了调试器。结果:没有人获得任何钱。

In your case, what you did was grab Visual Studio and say "Okay, we now have a joint bank account!" Now look what happens: Visual Studio cannot withdraw any money because it needs you to go to the bank. But you can't go to the bank because you're broken into the debugger. Result: Nobody gets any money.

您的设计从根本上是有缺陷的。

Your design is fundamentally flawed. You need to re-examine your situation.

另请参阅:我警告你:附加输入队列的危险

这篇关于Visual Studio 2010挂起时我调试方法AttachThreadInput()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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