Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7028591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:25:49+00:00 2026-05-28T00:25:49+00:00

I refactored my application a while ago and since then I’ve been having problems

  • 0

I refactored my application a while ago and since then I’ve been having problems with debugging using Visual Studio 2010.

My application works as expected while not debugging (not stepping through the application. An attached debugger does not cause any issues). However, when a breakpoint is triggered and I start to step through the app, Visual Studio and the app both hang after at most 3-4 steps.
To emphasize this point even more: It works well with my customers and regardless of whether I start it from Visual Studio or stand-alone – as long as no break point is triggered.
It does not matter where in the code I place the break point.

IDE: Visual Studio 2010 x64
Platform: .NET 4.0

The refactoring included a lot of cross-thread calls to BeginInvoke – all channeled through the following method:

public static void BeginInvokeIfRequired(this Control control, Action action)
{
    if (control.InvokeRequired)
    {
        control.BeginInvoke(action);
    }
    else
    {
        action.Invoke();
    }
}

There is not a single call to Control.Invoke() in the project.

  • Is there something wrong with the above method?

Additionally, I’d appreciate any hints on how you would track down this bug. My current approach is to add output to the console and selectively deactivating parts of the code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:25:50+00:00Added an answer on May 28, 2026 at 12:25 am

    I would suspect that in some cases the code you show poses a problem since InvokeRequired lies in case IsHandleCreated is false – it returns false even if you are not on the GUI thread.

    For reference see http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invokerequired.aspx .

    The following code throws an exception instead of hanging… the fact that it “works as expected” when no breakpoint is hit might be a result of the debugger freezing all threads on hitting a breakpoint which in turn might lead to a different order of execution etc.

    Altogether this means: you might have some “race condition” in your code where BeginInvokeIfRequired is called on a freshly created control before that control has a Handle. This can even be some 3rd-party code you use…

    public static void BeginInvokeIfRequired(this Control control, Action action)
    {
        if (control.IsHandleCreated)
        {
            if (control.InvokeRequired)
            {
                control.BeginInvoke(action);
            }
            else
            {
                action.Invoke();
            }
        }
        else { 
             // in this case InvokeRequired might lie ! 
             throw new Exception ( "InvokeRequired is possibly wrong in this case" );
             }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I refactored a slow section of an application we inherited from another company to
I have refactored some UIView sub-classes into a static library. However, when using Interface
Greetings! I inherited a C#.NET application I have been extending and improving for a
I've recently refactored my application with the following: Linq to SQL db connection Objects
I've been working on a Composite WPF application and just read some good guidelines
Since the datastructure of my application domain is becoming pretty complex as of late,
I am using Single data context per atomic operation approach while using Linq to
A while back I wrote an application which used Spring AOP for defining which
i've recently refactored a medium sized application and one of the jobs was to
I am developing a new media playback application for Digital cinema. While checking the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.