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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:21:54+00:00 2026-05-14T14:21:54+00:00

In my .NET application I am subscribing to events from another class. The subscription

  • 0

In my .NET application I am subscribing to events from another class. The subscription is conditional. I am subscribing to events when the control is visible and de-subscribing it when it become invisible. However, in some conditions I do not want to de-subscribe the event even if the control is not visible as I want the result of an operation which is happening on a background thread.

Is there a way through which I can determine if a class has already subscribed to that event?

I know we can do it in the class which will raise that event by checking the event for null, but how do I do it in a class which will subscribe to that event?

  • 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-14T14:21:55+00:00Added an answer on May 14, 2026 at 2:21 pm

    The event keyword was explicitly invented to prevent you from doing what you want to do. It restricts access to the underlying delegate object so nobody can directly mess with the events handler subscriptions that it stores. Events are accessors for a delegate, just like a property is an accessor for a field. A property only permits get and set, an event only permits add and remove.

    This keeps your code safe, other code can only remove an event handler if it knows the event handler method and the target object. The C# language puts an extra layer of security in place by not allowing you to name the target object.

    And WinForms puts an extra layer of security in place so it becomes difficult even if you use Reflection. It stores delegate instances in an EventHandlerList with a secret “cookie” as the key, you’d have to know the cookie to dig the object out of the list.

    Well, don’t go there. It is trivial to solve your problem with a bit of code on your end:

    private bool mSubscribed;
    
    private void Subscribe(bool enabled)
    {
        if (!enabled) textBox1.VisibleChanged -= textBox1_VisibleChanged;
        else if (!mSubscribed) textBox1.VisibleChanged += textBox1_VisibleChanged;
    
        mSubscribed = enabled;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My .NET application fails when run from a network drive even when the very
The .NET application for which I'm responsible uses a third-party control that is only
Net application and from one page i have to redirect to silverlight page, i
net application, in which i am using some popup windows to open some pages.
In our ASP.NET application we perform some initializations upon the Application Start event. When
N-Layered ASP.NET Application: One class library for all my layers or one class library
I have an ASP.NET application all things are working fine but after some minutes
I have an Asp.NET application (VS2008, Framework 2.0). When I try to set a
I have a ASP.NET application that we've written our own logging module for. My
Simple ASP.NET application. I have two drop-down controls. On the first-drop down I have

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.