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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:29:50+00:00 2026-06-05T02:29:50+00:00

I cant’find an answer to this simple question: is BeginInvoke() guaranteed to execute atomically

  • 0

I cant’find an answer to this simple question: is BeginInvoke() guaranteed to execute atomically the called delegate?
For instance, if I have something like

public ObservableCollection<string> Items;
public int TotalLenght;

delegate void AddItemDelegate(string arg);
Dispatcher _dispatcher=Dispatcher.CurrentDispatcher;

void StartExecute()
{
    for (int index = 0; index < 10; index++)
    {
        Thread th=new Thread(Run);
        th.Start();
    }
}

void Run()
{
    string item = DoLongRandomDuringCalculations(); 
    _dispatcher.BeginInvoke(new AddItemDelegate(AddItem), item);
}

void AddItem(string item)
{
    Items.Add(item);
    TotalLength += item.Length;
    TakeSnapshot();
}

can I stay assured that updates to the collection and the other member always are in sync, also if a calculation thread calls BeginInvoke exactly while another thread is in the middle of updating?

  • 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-05T02:29:52+00:00Added an answer on June 5, 2026 at 2:29 am

    You’ll get strong guarantees from the fact that all invoked methods run on the same thread. So by design they must run in order and can never overlap. So the Items collection is entirely safe and no locking is required, atomicity is not an issue.

    The exact order of items in the collection when the threads complete is however entirely non-deterministic.

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

Sidebar

Related Questions

Cant seem to find the answer to this, I'm sure it's simple, but just
I cant find a solution to this simple problem. I want to replace two
I cant seem to find the answer to this, mainly because I don't know
I cant find an answer to this that I understand. I want with JavaScript
Cant seem to find the answer to this. My code looks like this: var
cant seem to find a definintive answer to how to add a library. theres
Cant figure this simple sql out. crm_contact_id is updated with the same contact id
Cant really find any useful information on this through Google so hope someone here
I cant seem to find any info on this other than: Internet Explorer Embedded
Cant figure this out (am a noob) but I have a default activity that

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.