473,659 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

raising events by name

buu
So, let's say that a user enters an event name in text box, and would like
to raise it..
is it possible to call events by their 'name'?
Is it possible to enumerate events inside app. and to check their names?

Jul 1 '08 #1
26 1649
Is it possible to enumerate events inside app. and to check their names?
Yes; via reflection or System.Componen tModel. This lets you add/remove
event subscriptions, but it doesn't allow you to invoke the event.
Unless you hack about, you only have access to the *public* part of the
event, which (in C# at least) is just the add/remove accessor methods.
The underlying delegate is *often* a private field, but could also be in
an EventHandlerLis t, a Dictionary<,>, or on some parent/child instance.

In short, there is no robust single way of doing this for arbitrary classes.

Marc

Jul 1 '08 #2
buu,

As a user enters a name in a box, then that is not an event beside the
entering of the data.

The keys used to enter are events, the action done by what is entered has
nothing to do with an event.

You mix up an event by a simple action that you can do with a conditional
operator.

Cor

"buu" <ah*@a.comschre ef in bericht
news:12******** *******@news.vm ware.amis.hr...
So, let's say that a user enters an event name in text box, and would like
to raise it..
is it possible to call events by their 'name'?
Is it possible to enumerate events inside app. and to check their names?
Jul 1 '08 #3
buu
I took a wrong example..
but, lets say that I would like to raise up some events wich I know only by
name
"Cor Ligthert[MVP]" <no************ @planet.nlwrote in message
news:11******** *************** ***********@mic rosoft.com...
buu,

As a user enters a name in a box, then that is not an event beside the
entering of the data.

The keys used to enter are events, the action done by what is entered has
nothing to do with an event.

You mix up an event by a simple action that you can do with a conditional
operator.

Cor

"buu" <ah*@a.comschre ef in bericht
news:12******** *******@news.vm ware.amis.hr...
>So, let's say that a user enters an event name in text box, and would
like to raise it..
is it possible to call events by their 'name'?
Is it possible to enumerate events inside app. and to check their names?

Jul 1 '08 #4
>I took a wrong example..
but, lets say that I would like to raise up some events wich I know only
by name
You are not able to raise up an event, it is something that comes from the
OS.

However normally you can call the method. As you need reflection for this,
then there is mostly something terrible wrong in your program. (Or you
should not have the source anymore and are only able to use the DLL. But
that seems strange to me, how do you then know the name).

Cor

Jul 2 '08 #5
Buu,

I forgot to tell, some people comming from a scripting envirorment, try when
they first start with real programs, to use the way they used in the
scripting environment. Scripting has the bad habbit that it is slow and less
secure then pre builded exe and dll's.

However, as you real want this, you can create better array's with words,
and with that when they are equal start a method, instead of going the very
slow and insecure method of reflection.

Cor

"buu" <ah*@a.comschre ef in bericht
news:12******** ******@news.vmw are.amis.hr...
>I took a wrong example..
but, lets say that I would like to raise up some events wich I know only
by name
"Cor Ligthert[MVP]" <no************ @planet.nlwrote in message
news:11******** *************** ***********@mic rosoft.com...
>buu,

As a user enters a name in a box, then that is not an event beside the
entering of the data.

The keys used to enter are events, the action done by what is entered has
nothing to do with an event.

You mix up an event by a simple action that you can do with a conditional
operator.

Cor

"buu" <ah*@a.comschre ef in bericht
news:12******* ********@news.v mware.amis.hr.. .
>>So, let's say that a user enters an event name in text box, and would
like to raise it..
is it possible to call events by their 'name'?
Is it possible to enumerate events inside app. and to check their names?

Jul 2 '08 #6
Cor Ligthert[MVP] <no************ @planet.nlwrote :
I took a wrong example..
but, lets say that I would like to raise up some events wich I know only
by name
You are not able to raise up an event, it is something that comes from the
OS.
That entirely depends on the event. Look at BindingList<T>. ListChanged,
for example, or the events in my own Push LINQ stuff, or the various
events in ASP.NET.

Conceptually, events have nothing to do with the OS. In a GUI they're
usually tied to something which the operating system has informed the
program about, but that's a very specific example.
However normally you can call the method. As you need reflection for this,
then there is mostly something terrible wrong in your program. (Or you
should not have the source anymore and are only able to use the DLL. But
that seems strange to me, how do you then know the name).
Agreed. The whole point of events is to encapsulate
subscribe/unsubscribe, not raise or replace.

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jul 2 '08 #7
Jon

<snip>
Conceptually, events have nothing to do with the OS. In a GUI they're
usually tied to something which the operating system has informed the
program about, but that's a very specific example.
<snip>
Agreed, however invoking an event not direct, is because that you can not
control it direct. I tell it in this way just to make it simple. I knew that
once there would be someone who would tell this was not correct.

:-)

Cor
Jul 3 '08 #8
Cor Ligthert [MVP] <no************ @planet.nlwrote :
<snip>
Conceptually, events have nothing to do with the OS. In a GUI they're
usually tied to something which the operating system has informed the
program about, but that's a very specific example.
<snip>
Agreed, however invoking an event not direct, is because that you can not
control it direct. I tell it in this way just to make it simple. I knew that
once there would be someone who would tell this was not correct.
I'm not sure how bringing the OS into the picture unnecessarily (and
incorrectly) makes it simpler though. To my mind it complicates it for
no reason.

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jul 3 '08 #9
Let me give you a very good example where I need to be able to raise
events by using reflection.

I have an application using another UI system than the one provided by
.Net (In my case, a Flash File processed and displayed by a 3rd party
library).

So I implemented my own GUI classes such as button, textbox, etc. that
map the controls of the Flash UI, and implemented a class that
interfaces the Flash with my GUI classes (call it UIEngine).

When I receive events from that Flash file, the cleanest, most elegant
way of making my GUI classes work would have been to be able to raise
the corresponding events from that UIEngine class, using the event name
provided by the Flash library.

Well, with the actual C#, there is no clean way to do it.

Basically it means:

With C#, you can't make your own UI API, you can't implement your own
'OS' in an elegant way. You need to make this work with a workaround,
from the side, using some methods to raise your events for example,
making C# not so elegant on this aspect, as you are forced to write ugly
code to make your thing work in an elegant way.

C++/CLI allows it. VB.Net allows it. Why not C#?

*** Sent via Developersdex http://www.developersdex.com ***
Jul 3 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2091
by: serge calderara | last post by:
Dear all, I have a class wich is raising events as normally it should do. having a form in the same assembly wich is catching those events works fne. Raise events gets catch normaly within the form and I can process what I want based on them. If I try to catch raised events by this class but within a form located in a different assembly, I am not able to
9
4511
by: CW | last post by:
I wrote an HTML based chat application. The front end is built entirely on HTML + javascript. Essentially, I have a hidden frame that's refreshed frequently and any new messages are displayed in another frame using document.write. My problem is that since chat screen can be obscured by other applications/windows, I have no way of informing users that new messages have arrived other than popping the window to the top using window.focus....
6
2865
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a TimerState object similar to the example in the System.Threading.Timer documentation. The method which handles the timer events, among other things, periodically calls a method in this TimerState object which raises an event to the startup form,...
7
2438
by: cider123 | last post by:
I'm coding a project using the following article as reference: http://www.codeproject.com/csharp/DynamicPluginManager.asp In this type of project, plugins are loaded dynamically into a Plugin Manager. Your main application then hooks into the Plugin Manager. What I'm trying to figure out is how to impliment some form of raising
0
1721
by: Greg Park | last post by:
I have many user controls loading into a web page using Page.LoadControl However, I'm unable to figure out how to raise an event when a button is click or a check box is checked. I can have upto a hundred user controls on a single page and AutoPostBack isn't an option. I have no problem with raising events when an user control is dropped on the aspx page.
0
1444
by: Joe Campbell | last post by:
I am encountering a problem raising WMI events from an asp.net application. The error received (as captured in the event log) is as follows: System.Runtime.InteropServices.COMException (0x80041003): Exception from HRESULT: 0x80041003. at Microsoft.EnterpriseInstrumentation.EventSinks.WmiEventSink ..Write(Object eventToRaise) at
4
1592
by: Dave A | last post by:
I am developing a somewhat complex component at the moment and coincidently I am also reading the Framework Design Guidelines book. After reading the section about event raising I have re-written the way my component raises events to follow the Framework Design Guides verbatim; ie (object sender, EventArgs (or some subclass there of) e). The thing that was not explained is why should I need to cast the sender to 'object' when I know...
2
1692
by: Gman | last post by:
Hi, I have created a usercontrol, a grid control essentially. Within it I have a class: clsGridRecord. I have coded the events such that when a user clicks on the grid, say, the events occur on the parent form. This is fine. The problem occurs when I want to raise an event for a user clicking on one of the clsRecords which are on the grid. So I've placed: Public Event GridRecordClicked(ByVal rec As clsGridRecord,
0
1248
by: Apu Nahasapeemapetilon | last post by:
Suggestions on cross-posting this issue would be appreciated. I've got a C# .NET DLL (CLR v1.1) that raises events into its container. When the container is a .NET application, raising the events work everytime. When the container is Internet Explorer, raising the events work on some PCs, but generate the exception: "object does not match target type" on some other PCs.
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.