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 8496269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:48:20+00:00 2026-06-10T23:48:20+00:00

I was looking at the code within the OpenNETCF SDF BackgroundWorker implementation for the

  • 0

I was looking at the code within the OpenNETCF SDF BackgroundWorker implementation for the .NET compact framework and it looks like the following code is not thread-safe. But the Smart Device Framework has been around for ages, so what am I missing? Is this thread-safe and if so, why?

Note that I’m not inclined to post the whole class becasue, even though the SDF is free to use, the expectation is that customers pay for licenses to the SDF. If any of the SDF team object to even this educational excerpt then I will pull the question immediately.

This is the background thread that dequeues method invocations to invoke them on the UI thread:

private void ProgressDispatcherProc()
{
    this.m_stopThreads = false;
    while (!this.m_stopThreads)
    {
        while (this.m_progressQueue.Count > 0)
        {
            MethodInvoker method = null;
            ProgressChangedEventArgs args = this.m_progressQueue.Dequeue();
            if (this.ProgressChanged != null)
            {
                if (method == null)
                {
                    method = () => this.ProgressChanged(this, args);
                }
                this.m_guiMarshaller.BeginInvoke(method);
                Application.DoEvents();
            }
        }
        Thread.Sleep(this.WorkerReportsProgress ? 5 : 0x3e8);
    }
}

The variable m_progressQueue is a standard System.Collections.Generic.Queue<>.

My concern is there is no locking to protect the queue, which is enqueued in one thread and dequeued in this one. The looping on a simple boolean done in while (!this.m_stopThreads) I assume is safe enough because, as I understand it, in the .NET Compact Framework, all variable accesses treated as volatile.

  • 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-10T23:48:22+00:00Added an answer on June 10, 2026 at 11:48 pm

    I’d agree that it should have a lock, at least around the Dequeue call, something like this:

    lock(m_progressQueue.SyncRoot)
    {
        ProgressChangedEventArgs args = this.m_progressQueue.Dequeue(); 
    }
    

    And it could probably use them in the rest of the class.

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

Sidebar

Related Questions

I was looking into using some .NET code from within a Delphi program, I
I'm looking at code, and I'm not certain of its functionality. I looked at
I am looking to obfuscate our Java web app code within our existing Ant
So essentially I'm looking for specifically a 4 digit code within two angle brackets
I am totally new to Android development. I'm not looking for code but what
I'm looking for a tool like SonarJ but for .NET instead of Java. SonarJ
The deceptively simple foundation of dynamic code generation within a C/C++ framework has already
I've been looking into the use of the Unicode 'N' constant within my code,
I would like to call a windows program within my code with parameters determined
I'd like to use a plugin system within my code. I've looked around for

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.