471,355 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,355 software developers and data experts.

Access method variables/functions from Event call

Ok i understand the fact that once events are raised they are executed
on another thread and have no access to member functions or variables
because they are static functions.

But i am having trouble how i can Invoke these methods from the static
method.

Can anyone help me out here? :)

TIA!

Jun 5 '07 #1
2 1814
Ahmed,

This isn't true. Events are executed on the thread that they are raised
on. When the events are fired on another thread, it is because they are
raised on that thread.

Also, event handlers can be static methods, or instance methods. You
can attach an event handler to an instance method, and then access all the
members of that instance in the event handler (since it is just another
member).

So instead of attaching to a static method, why not attach to an
instance method which has access to the members you need?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ahmed" <ah*****@gmail.comwrote in message
news:11**********************@x35g2000prf.googlegr oups.com...
Ok i understand the fact that once events are raised they are executed
on another thread and have no access to member functions or variables
because they are static functions.

But i am having trouble how i can Invoke these methods from the static
method.

Can anyone help me out here? :)

TIA!
Jun 5 '07 #2
wow you are right! Ok my book on C# is really misleading and all its
templates are based on static functions which led me to believe it HAD
to be a static function.

Thanks for the help! :)
Ahmed

On Jun 5, 5:21 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Ahmed,

This isn't true. Events are executed on the thread that they are raised
on. When the events are fired on another thread, it is because they are
raised on that thread.

Also, event handlers can be static methods, or instance methods. You
can attach an event handler to an instance method, and then access all the
members of that instance in the event handler (since it is just another
member).

So instead of attaching to a static method, why not attach to an
instance method which has access to the members you need?

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"Ahmed" <ahme...@gmail.comwrote in message

news:11**********************@x35g2000prf.googlegr oups.com...
Ok i understand the fact that once events are raised they are executed
on another thread and have no access to member functions or variables
because they are static functions.
But i am having trouble how i can Invoke these methods from the static
method.
Can anyone help me out here? :)
TIA!

Jun 5 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by quo | last post: by
7 posts views Thread by Joakim Braun | last post: by
6 posts views Thread by Peter Frost | last post: by
49 posts views Thread by Yannick Turgeon | last post: by
6 posts views Thread by David Sullivan | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.