Hi
I am currently creating a WLAN simulation problem and have encountered a
problem...
I have two classes (Channel and RadioLayer), and for instance create the
following objects:
Channel channel = new Channel();
RadioLayer Radio1 = new RadioLayer();
RadioLayer Radio2 = new RadioLayer();
What I would like to do is to raise an Event in the channel object (no
problem) and only trap this event in Radio1 and not in Radio2 (the
problem!)... Is there a nice way to do this?
I am trying to use events as an interface between the layers, because it
makes it much easier to create new components with new functionality, but it
is causing me some problems. A solution could be to raise the event, and
then parse the event for relevance in all of the RadioLayer object, but
since there can be a lot of those, I think it will degrade my performance a
lot.
I am currently using VS2003, so is there improvements that will help me in
this situation in dotnet 2.0 (VS2005)?
Is there another smart way to solve the problem?
I am looking forward to your comments...
Regards...
Thorbjørn 7 1450
Hi,
You have to subscribe to events explicitly in C#. Therefore, it is you who
chooses whether to listen to a particular event or not. For example, you can
pass a flag to the RadioLayer's constructor to indicate whether this
instance of RadioLayer should subscribe to the underlying channel's events.
--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Thorbjørn Jørgensen softdoc.dk>" <thorbjorn@<REMOVE> wrote in message
news:43***********************@news.sunsite.dk... Hi
I am currently creating a WLAN simulation problem and have encountered a problem...
I have two classes (Channel and RadioLayer), and for instance create the following objects:
Channel channel = new Channel();
RadioLayer Radio1 = new RadioLayer();
RadioLayer Radio2 = new RadioLayer();
What I would like to do is to raise an Event in the channel object (no problem) and only trap this event in Radio1 and not in Radio2 (the problem!)... Is there a nice way to do this?
I am trying to use events as an interface between the layers, because it makes it much easier to create new components with new functionality, but it is causing me some problems. A solution could be to raise the event, and then parse the event for relevance in all of the RadioLayer object, but since there can be a lot of those, I think it will degrade my performance a lot.
I am currently using VS2003, so is there improvements that will help me in this situation in dotnet 2.0 (VS2005)? Is there another smart way to solve the problem? I am looking forward to your comments... Regards...
Thorbjørn
Hi You have to subscribe to events explicitly in C#. Therefore, it is you who chooses whether to listen to a particular event or not. For example, you can pass a flag to the RadioLayer's constructor to indicate whether this instance of RadioLayer should subscribe to the underlying channel's events.
I might just have explained this badly and given a not so good example...
The followring example might be better...
I have an RadioLayer and a DataLinkLayer class, and create the followring
object.
RadioLayer Radio1 = new RadioLayer();
DataLinkLayer DataLink1 = new DataLinkLayer();
RadioLayer Radio2 = new RadioLayer();
DataLinkLayer DataLink2 = new DataLinkLayer();
What I would like to happen, is that Radio1 can raise an event (for instance
when a packet arrive) and that this event only will be traped by DataLink1
and not DataLink2... And when Radio2 raise an event that will only be traped
by DataLink2...
Is there a way to do this?
Regards
Thorbjorn
Thorbjorn Jorgensen wrote: Hi
You have to subscribe to events explicitly in C#. Therefore, it is you who chooses whether to listen to a particular event or not. For example, you can pass a flag to the RadioLayer's constructor to indicate whether this instance of RadioLayer should subscribe to the underlying channel's events.
I might just have explained this badly and given a not so good example... The followring example might be better... I have an RadioLayer and a DataLinkLayer class, and create the followring object. RadioLayer Radio1 = new RadioLayer(); DataLinkLayer DataLink1 = new DataLinkLayer(); RadioLayer Radio2 = new RadioLayer(); DataLinkLayer DataLink2 = new DataLinkLayer();
What I would like to happen, is that Radio1 can raise an event (for instance when a packet arrive) and that this event only will be traped by DataLink1 and not DataLink2... And when Radio2 raise an event that will only be traped by DataLink2... Is there a way to do this?
Dmytro did in fact answe your question. You haven't given any
information about how these objects know about each other, so we must
assume that you are hooking up events manually. Doing this, only those
event handlers you *explicitly* hook up will respond to events
happening.
So if RadioLayer has an event called PacketArrived, and you do this:
Radio1.PacketArrived += DataLink1.PacketArrivedHandler;
Radio2.PacketArrived += DataLink2.PacketArrivedHandler;
then yes, datalink2 will respond to packets on radio2, and datalink1
will respond to packets on radio1. No other handlers will respond to
these events - because you haven't asked them to! And if you *don't*
execute these lines (or something like them), then nothing at all will
happen when packets arrive.
Events aren't like, say, Windows broadcast messages, which get sent to
everyone whether they have asked for them or not. Listeners must
*subscribe* to events in order to be informed when the event fires.
--
Larry Lard
Replies to group please
Hi
First of all, thank you both very much for your replies. I do not doubt that
you both ansewered my question perfectly... I just did not understand the
answer, and tried again... and still got some questions... Dmytro did in fact answe your question. You haven't given any information about how these objects know about each other, so we must assume that you are hooking up events manually. Doing this, only those event handlers you *explicitly* hook up will respond to events happening.
So if RadioLayer has an event called PacketArrived, and you do this:
Radio1.PacketArrived += DataLink1.PacketArrivedHandler; Radio2.PacketArrived += DataLink2.PacketArrivedHandler;
Well I tried this, but can not make it work...
I can see that I have created the RadioLayer with the PacketArrived
correctly, since the event i shown in the Class viewer, as an Event. But
when I try to do the above it gets an error: "Static member
'RadioLayer.PacketArrived' cannot be accessed with an instance reference;
qualify it with a type name instead"...
Well, I can do the followring:
RadioLayer.PacketArrived += Some function...
But then all events created in all RadioLayer obejct will create an event
that is traped by the listener...
Is this because I use VS2003 or have I just made some stupid error?
Regards
Thorbjørn
Thorbjørn Jørgensen <thorbjorn@ wrote: Hi First of all, thank you both very much for your replies. I do not doubt that you both ansewered my question perfectly... I just did not understand the answer, and tried again... and still got some questions...
Dmytro did in fact answe your question. You haven't given any information about how these objects know about each other, so we must assume that you are hooking up events manually. Doing this, only those event handlers you *explicitly* hook up will respond to events happening.
So if RadioLayer has an event called PacketArrived, and you do this:
Radio1.PacketArrived += DataLink1.PacketArrivedHandler; Radio2.PacketArrived += DataLink2.PacketArrivedHandler;
Well I tried this, but can not make it work... I can see that I have created the RadioLayer with the PacketArrived correctly, since the event i shown in the Class viewer, as an Event. But when I try to do the above it gets an error: "Static member 'RadioLayer.PacketArrived' cannot be accessed with an instance reference; qualify it with a type name instead"... Well, I can do the followring: RadioLayer.PacketArrived += Some function... But then all events created in all RadioLayer obejct will create an event that is traped by the listener...
Is this because I use VS2003 or have I just made some stupid error?
Regards Thorbjørn
Thorbjørn:
I only know C++, but I'm sure it's similar:
RadioLayer Radio1 = new RadioLayer();
DataLinkLayer DataLink1 = new DataLinkLayer(Radio1);
RadioLayer Radio2 = new RadioLayer();
DataLinkLayer DataLink2 = new DataLinkLayer(Radio2);
Constructor:
DataLinkLayer(RadioLayer radio)
{
radio.PacketArrived += PacketArrivedHandler;
}
It's just standard OOP communication.
David Wilkinson
Hi I only know C++, but I'm sure it's similar:
RadioLayer Radio1 = new RadioLayer(); DataLinkLayer DataLink1 = new DataLinkLayer(Radio1); RadioLayer Radio2 = new RadioLayer(); DataLinkLayer DataLink2 = new DataLinkLayer(Radio2);
Constructor:
DataLinkLayer(RadioLayer radio) { radio.PacketArrived += PacketArrivedHandler; }
It's just standard OOP communication.
I think that I might have created the Events wrongly, cause if I try the
same with a System.Windows.Forms.Button object I can access events in the
way described... but if I try with the classes I created I can not access
the events when an object is instanced...
This is the basic functionality of the RadioLayer class:
public class PacketEventArgs : EventArgs
{
public PacketEventArgs(Packet packet)
{
}
public Packet packet;
}
public delegate void PacketArrivedHandler(PacketEventArgs packetEvent);
public class RadioLayer
{
public static event PacketArrivedHandler PacketArrived;
public static void OnPacketArrived(PacketEventArgs packetEvent)
{
if(PacketArrived!=null)
PacketArrived(packetEvent);
}
}
But if I create a RadioLayer object, I can not access the PacketArrived
event with the VS autocomplete... What have I done wrong in this code?
Regards
Thorbjørn
Hi
Thank you all for you answers...
I have found the error... I was a little too quickly to copy from an example
and had made the Event static, hence the entire problem...
I am sorry to have been interrupted you with this silly question :-)
Regards
Thorbjørn This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Vince C. |
last post by:
Hi.
I'd like to trap ADO Recordset object events in my ASP script (either VBS or JS,
no preference). I've tried (in VBS) writing a Sub rs_RecordChangeComplete(
adReason, cRecords, pError,...
|
by: RAJ |
last post by:
hi
plz tell me how to know "how window is going to close"...
i have to right code for X button of forms...
plz telll me
thanks
bye
|
by: COLIN JACK |
last post by:
Hi All,
I've got a situation where I'm implementing an interface (BaseInterface in
example below) and I want to use explicity interface implementation of an
event so that I can add type safety. ...
|
by: pemo |
last post by:
Ambiguous?
I have a student who's asked me to explain the following std text (esp. the
footnote).
6.2.6.1.5
Certain object representations need not represent a value of the object
type. If...
|
by: ABC |
last post by:
I want to check the form's controls have or not the specific properties or
events. How to determine or gather the properties list under the run-time
environment?
|
by: pemo |
last post by:
As far as I understand it, a trap representation means something like -
an uninitialised automatic variable might /implicitly/ hold a bit-pattern
that, if read, *might* cause a 'trap' (I'm not...
|
by: Bill Schmidt |
last post by:
I am attempting to send an SNMP trap using C#. however I have been
unable to find a way to do it. websearching has turned up a small
number of 3rd party tools that should be able to do this,...
|
by: mavigozler |
last post by:
IE7 does not appear to set an event on contained text inside SPAN elements
whose 'onclick', 'onmouseover', and 'onmouseout' events, defying the HTML
recommendation. Firefox appears to conform.
...
|
by: swethak |
last post by:
Hi,
I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |