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

  • Home
  • SEARCH
  • 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 110097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:10:24+00:00 2026-05-11T02:10:24+00:00

Basic premise: I have a Room which publishes an event when an Avatar enters

  • 0

Basic premise:

I have a Room which publishes an event when an Avatar ‘enters’ to all Avatars within the Room. When an Avatar leaves the Room I want it to remove all subscriptions for that room.

How can I best unsubscribe the Avatar from all events in the room before I add the Avatar to a new Room and subscribe to the new Room’s events?

The code goes something like this:

class Room {    public event EventHandler<EnterRoomEventArgs> AvatarEntersRoom;    public event EvnetHandler<LeaveRoomEventArgs> AvatarLeavesRoom;    public event EventHandler<AnotherOfManyEventArgs> AnotherOfManayAvatarEvents;      public void AddPlayer(Avatar theAvatar)    {       AvatarEntersRoom(this, new EnterRoomEventArgs());         AvatarEntersRoom += new EventHandler<EnterRoomEventArgs>(theAvatar.HandleAvatarEntersRoom);        AvatarLeavesRoom += new EventHandler<EnterRoomEventArgs>(theAvatar.HandleAvatarEntersRoom);        AnotherOfManayAvatarEvents += new EventHandler<EnterRoomEventArgs>(theAvatar.HandleAvatarEntersRoom);               }  }  class Avatar {    public void HandleAvatarEntersRoom(object sender, EnterRoomEventArgs e)    {        Log.Write('avatar has entered the room');    }     public void HandleAvatarLeaveRoom(object sender, LeaveRoomEventArgs e)    {        Log.Write('avatar has left room');    }     public void HandleAnotherOfManayAvatarEvents(object sender, AnotherOfManyEventArgs e)    {        Log.Write('another avatar event has occurred');    } } 
  • 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. 2026-05-11T02:10:24+00:00Added an answer on May 11, 2026 at 2:10 am

    Each delegate has a method named GetInvocationList() that returns all the actual delegates that have been registered. So, assuming the delegate Type (or event) is named say MyDelegate, and the handler instance variable is named myDlgHandler, you can write:

    Delegate[] clientList = myDlgHandler.GetInvocationList(); foreach (var d in clientList)        myDlgHandler -= (d as MyDelegate); 

    to cover the case where it might be null,

     if(myDlgHandler != null)   foreach (var d in myDlgHandler.GetInvocationList())        myDlgHandler -= (d as MyDelegate); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Winform with a very basic premise: modify 2 string properties of
What is the basic premise behind technology such as is found in Oblivion (and
I am writing a minimal replacement for mod_python's publisher.py The basic premise is that
Basic requests are: human readable / text format (for easy version control) online (for
Basic question : How to I create a bidirectional one-to-many map in Fluent NHibernate?
The basic problem is like this: A subscriber has successfully replicated a row from
My basic question is, in .NET, how do I clone WebControls? I would like
Very basic question: how do I write a short literal in C++? I know
A basic definition and example and a few references for X-Macros is given in
Visual Basic allows for properties with mixed access levels, for example Public Property Name()

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.