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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:39:29+00:00 2026-05-26T09:39:29+00:00

AFAIK, this event is promised to be called in the creator thread ( BackgroundWorker

  • 0

AFAIK, this event is promised to be called in the creator thread (BackgroundWorker RunWorkerCompleted Event); and in the most cases, it does as promised. However, sometimes RunWorkerCompleted is called not in the thread that created BackgroundWorker object.

Update: Code is like this:

Trace.WriteLine(Thread.CurrentThread.ManagedThreadId);
var worker = new BackgroundWorker();
worker.DoWork += (s, args) => Trace.WriteLine(Thread.CurrentThread.ManagedThreadId);
worker.RunWorkerCompleted += (s, args) => Trace.WriteLine(Thread.CurrentThread.ManagedThreadId);
worker.RunWorkerAsync();

Output is 1 7 7 (correct output must be 1 7 1)
Any ideas?

  • 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-26T09:39:30+00:00Added an answer on May 26, 2026 at 9:39 am

    BackgroundWorker is designed for GUI applications.

    I’m guessing you’re doing this in a console application or some other type of application other than Winforms or WPF.

    BackgroundWorker uses the synchronization model provided by SynchronizationContext.Current to dispatch events. In a GUI application, SynchronizationContext.Current is initialized with a WindowsFormsSynchronizationContext, which provides synchronization by Invoking on the UI thread.

    But in a non-GUI application, SyncronizationContext.Current is just a SynchronizationContext object, which (from MSDN):

    is a base class that provides a free-threaded context with no synchronization.

    In other words it simply dispatches via the threadpool, so you’ll usually get a different thread each time.

    If you run your code in a winforms application, it will work as expected.

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

Sidebar

Related Questions

We often use event handler in C#, just as below: some_event+=some_event_handler; Does this happen
AFAIK, for pointers/references static_cast, if a class definition is not visible to compiler at
in this sample , two threads created; a worker thread created by BeginInvoke and
I have a style template (below) that does not update when my Tag binding
How does one go about attaching a bunch of code to an onkeydown event,
This is a best practices type of question. AFAIK there are two approaches (and
Sorry if this is the wrong place, but I'm not sure what Stack Exchange
AFAIK one of the objectives of Stack Overflow is to make sure anyone can
AFAIK, Currency type in Delphi Win32 depends on the processor floating point precision. Because
AFAIK ROWID in Oracle represents physical location of a record in appropriate datafile. In

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.