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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:09:57+00:00 2026-05-13T01:09:57+00:00

I may be greatly misunderstanding this threading scenario, but that’s why I’m asking. What

  • 0

I may be greatly misunderstanding this threading scenario, but that’s why I’m asking.

What would/might happen in the following situation (assume C# threading)? Note: this scenario is simplified to the core issue, extra functionality is ignored.

I have 2 objects, a and b, which are instances of classes A and B respectively; ‘b’ is a member of ‘a’.

‘b’ is running a processing loop and has a few other activities continually doing something. At one point, ‘b’ detects a situation which causes it to send an event to ‘a’. When ‘a’ recieves this event, it executes the following code:

void b_eventFoo()
{
    b.UnhookEvents();//clears the delegate that truggered this event function
    this.b = new B();        
    b.HookEvents(this);//connects the new b object to this A
}

What happens to the old ‘B’ object? The original ‘b’ still is doing some processing and the very thread that triggered the event could still be executing. I don’t understand threading well enough to predict the results of this scenario.

Does it even matter?

Please let me know if I should clarify anything.

  • 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-13T01:09:57+00:00Added an answer on May 13, 2026 at 1:09 am

    At the start, you have:

    Thread1: [A1] -----field ----> [B1]
                  <--- event -----
    

    You create a new thread, running a loop on B1; the key here is that delegates and instance methods (during use) themselves have a reference to the instance (it is “arg0” in IL terms); so you have:

    Thread1: [A1] ---- field ----> [B1]
                  <--- event -----   ^
    Thread2: ------------------------^
    

    You then unhook the event and cancel the field:

    Thread1: [A1] ---- field ----> [nil]
    
    Thread2: --------------------> [B1]
    

    And recreate and rehook against a different instance:

    Thread1: [A1] ---- field ----> [B2]
                  <--- event -----
    
    Thread2: --------------------> [B1]
    

    So: your thread continues processing against [B1], but no longer impacts [A1]

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

Sidebar

Related Questions

This may be a tough one for you all, if it is even possible
This may well be a little of an open-ended question The site I am
If I have a layered application and my Data Layer may encounter an OptimisticConcurrencyException
How can using something like MSMQ help with scalability and reliability? In the scenario
I manage an enrollment website which needs some new features for our agents. What
I'm having trouble getting the windsor container and entity framework working together and it
Which Visual Studio \ Visual C++ file types should be committed to version control?
gleanings from a variety of sources (including stackOverlflow), however when I come to use
I am new to iphone, Is it possible to upload uiimage on server without
I am trying to create an MP3 audio file on the device (iPhone). I

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.