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

  • SEARCH
  • Home
  • 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 8684301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:16:16+00:00 2026-06-12T22:16:16+00:00

I get an very strange behaviour when I change my Visual Studio 2010 config

  • 0

I get an very strange behaviour when I change my Visual Studio 2010 config from Debug to Release:

I have a BackgroundWorker: _bg, in the DoWork I have:

                iswaiting = true;
                _bg.ReportProgress(1, filePath);
                while (iswaiting)
                {                        
                  ;
                }
                //My other part of code (EDIT: something do to with the `result` I get from the user.)

in the ProgressChanged I have a MessageBox and after the user interaction, iswaiting will be set back to false and the _bg DoWork program will continue.

 void _bg_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        //my other part of code........
       result = Microsoft.Windows.Controls.MessageBox.Show("Question" ,"Title", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);

       iswaiting=false; 
       log(iswaiting.toString());                  
    }

All of these works very well when I run it from Visual Studio or build in Debug mode, but when I build it to Release, I never get out of the while(iswaiting) loop, although I can see from the log iswaiting is already set back to false.

EDIT:

Better way of doing this is more than welcome!!

  • 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-06-12T22:16:18+00:00Added an answer on June 12, 2026 at 10:16 pm

    This is likely due to threading optimizations. In order to safely “see” the change in iswaiting in release mode, you need a memory barrier in place.

    The simplest way to “fix” this would be to mark iswaiting as volatile:

    volatile bool iswaiting;
    

    That being said, “spinning” like this will completely consume one CPU core. A much better approach would be to use a ManualResetEvent to signal that you can continue.

    // Add:
    private ManualResetEvent allowProgress = new ManualResetEvent(false);
    

    Then, instead of using iswaiting, you’d do:

    _bg.ReportProgress(1, filePath);
    allowProgress.WaitOne(); // This will block until it's set
    

    To allow this to continue, use:

     result = Microsoft.Windows.Controls.MessageBox.Show("Question" ,"Title", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
    
      allowProgress.Set();
    

    The advantage here is that you won’t consume CPU while you’re blocked, and you don’t have to worry about the memory barriers yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With the following simple mark-up, I get very strange behaviour in FF and IE8.
I'm seeing some very strange behaviour from the Apple Push Notification Servers when the
I'm fighting with a very strange behaviour in my Android app. I have a
I am experiencing a very strange behaviour of redgate that prevents me from commiting
We have a very strange behaviour of a WPF application. Sometimes (not very ofen),
This is a very strange behaviour. If I have something like this (time interval
I've noticed some very strange behaviour today in Code Igniter. I have this locations
i'm working with OpenSSL lib and get very strange effect with AES encrypt/decrypt: if
Very strange bug I can't seems to figure out. I am trying to get
I'm getting a very strange behaviour in one of my JSP pages. It looks

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.