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

The Archive Base Latest Questions

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

I need to access x and y properties of object obj(of type some ClassA)

  • 0

I need to access x and y properties of object obj(of type some ClassA) in the event handling method subscribed to an event in object obj.

Option1: Just make this event of type EventHandler, cast the sender.

void handlingMethod(object sender, EventArgs e)
{
    ClassA ca = sender as ClassA;
    Dosomething(ca.id, ca.x, ca.y);
}

RaiseEvent(this,null); //in ClassA

Option2:
Make a SpecialEventHandler1 so that casting can be avoided.

void handlingMethod(SpecialEventArgs e)
{
    Dosomething(e.id, e.x,e.y);
}

RaiseSpecialEvent1(new SpecialEventArgs(this.id, this.x,this.y));//in ClassA

Option3:
Make a SpecialEventHandler2 so that both casting and new SpecialEventArgs object creation can be avoided.

void handlingMethod(ClassA sender)
{
     Dosomething(sender.id, sender.x, sender.y);
}
RaiseSpecialEvent2(this); //in ClassA

Lets say this events are raised continuously @50/sec. Which one is more efficient? Does it depend on size of ClassA? I am assuming that Option3 is the best way in terms of performance. Please give your insights.

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

    50hz is not fast at all so your best bet is to stick with convention. This will make your code more approachable to new developers. Also remember to use a cast when you expect only one type so you can get a detailed exception if the event is raised incorrectly.

    void MyClassA_Something(object sender, EventArgs e)
    {
        ClassA ca = (ClassA)sender;
        Dosomething(ca.id, ca.x, ca.y);
    }
    

    Events really shouldn’t take too long but if they do you really need to offload it onto another thread. In either case though you should stick with the convention for events.

    void MyClassA_Something(object sender, EventArgs e)
    {
        ThreadPool.QueueUserWorkItem(o => {
            ClassA ca = (ClassA)sender;
            Dosomething(ca.id, ca.x, ca.y);
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm mocking up some data, and I need to be able to access properties
Let's assume I have some MyObject obj object and want to access a property
I need access to the uint64_t typedef from stdint.h in some wrapper code that
I need to access a php object property which I specify as variable. $phpObj->$property
i need to make an array of arraylists of an object. i have tried
I have a question about access to object properties that will be used in
With ARC sometimes I still need to write a -dealloc method to do some
I have object properties in my code that look like this: $obj ->field_name_cars[0]; $obj
I would like to have some sort of lazy initialied object properties in javascript
I have two different modules that need access to a single file (One will

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.