473,815 Members | 3,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Conditional events?

Hi,

I have a Sender and Reciever classes. I want the sender to send events
to reciever but given a condition specified by reciever.

For example, lets assume that sender is a keyboard and a reciever is a
console. Lets assume that keyboard sends event every time key is
pressed:

Standard way of adding event handlers:

//somewhere in console class initialization
keyboard.EventH andler += new SomeEventDelega te(this.OnEvent );

Now, if key is pressed, console will recieve an event from keyboard
and the key code can be included in SomeEventArgs structure.

The big question is, how can console provide information to the
keyboard on which keys it wants to listen (recieve events), in other
words to have something like this:

//somewhere in console class initialization
keyboard.AddHan dler(this.OnSpe cificKeyPressed , key);
Nov 16 '05 #1
2 4850
P. Gorecki,

You will have to add custom code to do this on your event producer.
Generally, I think that this is a bad idea, especially if you are providing
filters for individual subscribers. If you want individual subscribers to
filter themselves, then they have all the information that they need in the
event handler to make an informed decision.

If you want to filter the events to all subscribers, I would place a
property or method that will set the condition, and then have your event
firer check to make sure that condition is true when firing.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"P. Gorecki" <mc******@wp.pl > wrote in message
news:a2******** *************** ***@posting.goo gle.com...
Hi,

I have a Sender and Reciever classes. I want the sender to send events
to reciever but given a condition specified by reciever.

For example, lets assume that sender is a keyboard and a reciever is a
console. Lets assume that keyboard sends event every time key is
pressed:

Standard way of adding event handlers:

//somewhere in console class initialization
keyboard.EventH andler += new SomeEventDelega te(this.OnEvent );

Now, if key is pressed, console will recieve an event from keyboard
and the key code can be included in SomeEventArgs structure.

The big question is, how can console provide information to the
keyboard on which keys it wants to listen (recieve events), in other
words to have something like this:

//somewhere in console class initialization
keyboard.AddHan dler(this.OnSpe cificKeyPressed , key);

Nov 16 '05 #2
You could create a method which takes the delegate instance and the condition and internally wires up the event and stored the filter data. In other words you could have exactly what you have stated, an AddHandler method. You could store which delegates to invoke on which keys via a hashtable.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

Hi,

I have a Sender and Reciever classes. I want the sender to send events
to reciever but given a condition specified by reciever.

For example, lets assume that sender is a keyboard and a reciever is a
console. Lets assume that keyboard sends event every time key is
pressed:

Standard way of adding event handlers:

//somewhere in console class initialization
keyboard.EventH andler += new SomeEventDelega te(this.OnEvent );

Now, if key is pressed, console will recieve an event from keyboard
and the key code can be included in SomeEventArgs structure.

The big question is, how can console provide information to the
keyboard on which keys it wants to listen (recieve events), in other
words to have something like this:

//somewhere in console class initialization
keyboard.AddHan dler(this.OnSpe cificKeyPressed , key);

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.782 / Virus Database: 528 - Release Date: 22/10/2004

[microsoft.publi c.dotnet.langua ges.csharp]
Nov 16 '05 #3

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

Similar topics

4
3650
by: CGuy | last post by:
Hi, I have an ASPX page which has a datagrid and this datagrid is bound to a Custom Collection. sample code this.DataGrid1.DataSource = UserManager.Users; this.DataGrid1.DataBind();
28
3467
by: Benjamin Niemann | last post by:
Hello, I've been just investigating IE conditional comments - hiding things from non-IE/Win browsers is easy, but I wanted to know, if it's possible to hide code from IE/Win browsers. I found <!> in the original MSDN documentation, but this is (although it is working) unfortunately non-validating gibberish. So I fooled around trying to find a way to make it valid. And voila: <!--><!><!-->
4
3799
by: Andrew Ducker | last post by:
I've got a C# project that automatically kicks off NUnit whenever I do a build. I want to change this so that it only does so when I've got the Configuration set to NUnit. Is there any way to either set up the post-build event to be conditional, or have it be dynamic? Cheers,
1
4582
by: euan | last post by:
HI Guys, I have bee using conditional formatting in the datagrid recently and I am moving over to framework 2.0 and noticed the datagrid has been replaced by the gridview. So, I would like to do conditional formatting on the gridview but it doesnt have the same methods. Currently in my datagrid I have this (this is just hacked together randomly but gives you the idea):
1
1605
by: lavu | last post by:
Is there any way to specify a different executable name for my project based on value that I have set in my conditional compilation constant. For eg: If I have FIRST specified in my conditional compilation constant then I would like the executable to be XYZ.exe and if nothing is specified then the executable should be ABC.exe. Any ideas appreciated. Thanks in advance.
8
8519
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works perfectly. However, I have code that runs under the ON CLICK event. The code changes the focus to other controls, which means the conditional formatting is no longer displayed. This part makes sense to me. Here's what doesn't make sense. The last...
3
4189
by: Goose14 | last post by:
Is there a way to use conditional compilation symbols to change the output path for the build, change the exe name and also change the the exe icon? I have an application that has "skins". I use the symbols to change from one skin to another, but i'd like to streamline the process of compilation. Is this possible maybe via conditional symbols or pre build events?
1
2509
by: Earl Anderson | last post by:
A business colleague and I are collaborating 'long distance' on an applet for work. He is doing the programming and I am doing the business process form design. We had discussed my desire to make all of the textbox fields with the 'focus' become a 'light orange' in backcolor. He is working in A2k3/WinXP and I am working in A2002/WinXP (The users of the applet have A2k3). In our preliminary discussions about this particular enhancement,...
7
4315
by: tiptap | last post by:
Hey Guys, I have a huge statement loads of if statements in... and its getting bigger. On closer inspection there is only 3 difference in the select statement. so I thought I could cut the whole thing down to just 1 select statement if I have a conditional Having. I've simplified the IF statement down a bit to give you an idea of what im trying to achieve IF @month <> 0 & @diffFuture = 0 & @showDate <> 0
0
10672
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...
1
10428
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
10145
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
9226
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
7687
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...
0
5570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5710
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4359
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
3
3030
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.