none
Get EventHandler Change Notification without Creating Instance or Making it static RRS feed

  • Question

  • c# : Get EventHandler Change Notification without Creating Instance or Making it static

    Public class A
     {
       public  EventHandler KeyboardCloseEventHandlerTest;
       
       
        private void someMethod(object sender, EventArgs e)
             {             
                 KeyboardCloseEventHandlerTest?.Invoke(sender, e);           
             }
     }
     
     Public class B
     {
     public  EventHandler KeyboardCloseEventHandlerTest1;
     
         private void Tesssss(object sender, EventArgs e)
         {             
         }
     
     }

    I need class A EventHandler to registered in Class B and Fire Class Method.

    I can't make anything static not create a instance. More Importantly it should not cause performance Issue.

    Friday, April 3, 2020 6:42 PM

All replies

  • Is there any other way... Other there is no way to solve this problem
    Sunday, April 5, 2020 4:35 PM
  • The B object somehow needs to have access to the A object that needs to send the event.  As long as that's true, then it's easy.

        class B {
            public void RegisterEvents( A myAobject )
            {
                 myAobject.KeyboardCloseEventHandlerTest1 += Tessssss;
            }
        }


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Monday, April 6, 2020 12:45 AM
  • I did try this approach mate, ur correct how can I raise an event in b..without making static nor create instance
    Monday, April 6, 2020 1:44 AM