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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:04:57+00:00 2026-06-09T23:04:57+00:00

pseudo-code: class A { Dictionary<string, object> dic = new Dictionary<string, object>(); public Do() {

  • 0

pseudo-code:

class A
{
    Dictionary<string, object> dic = new Dictionary<string, object>();
    public Do()
    {
        some_a.SomeEvent += (s, e) =>
                 {
                     dic["some_string"] = new object();
                 };   
         dic["some_other_string"] = new object();
    }
}

Is this safe? It would be if both dictionary operations were on single same thread. So are they?

EDIT In my situation event is fired in the same thread as Do, so it’s safe.

  • 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-09T23:04:58+00:00Added an answer on June 9, 2026 at 11:04 pm

    An event happens (usually) on the thread that invokes the event. So we can’t actually comment completely since you don’t show the code that causes the event to be invoked!

    Strictly speaking, the event could be on any thread – either because a random thread is calling OnSomeEvent (or whatever the trigger is), or if the OnSomeEvent implementation chooses to use BeginInvoke for some reason, but this is unlikely.

    Ultimately, it comes down to: is there a reason to think multiple threads are involved in this code.

    But: what absolutely is not the case: no, there is nothing that will make that event automatically happen on the thread that subscribes it. An event subscription is just an object+method pair; no thread is nominated in the subscription.

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

Sidebar

Related Questions

I have an object model that looks like this (pseudo code): class Product {
Today I encountered the following situation: (pseudo code) class MyClass { public void workOnArray(Object[]
I have written a custom server control which (pseudo-code) looks like public class MyCustomCtrl
This is best described in pseudo-code: class Thing {}; interface ThingGetter<T extends Thing> {
I have an AS3 App class e.g (pseudo code) public class MyApp extends Application
this is what I want to be able to do: (pseudo code) class DerivedClass
I have the (pseudo) code: public class GlobalClass { public GlobalClass() { var x
I have this (partially pseudo)code class a { void b() { int d =
Models (disregard typos / minor syntax issues. It's just pseudo-code): class SecretModel(models.Model): some_unique_field =
Please see my pseudo-code below. The code comments should explain my problem. I'm new

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.