473,375 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Directred Event Multicasting

Assume I have an n by n matrix of identical objects, each of which can both
invoke and consume event A. If, say, obect[1,2] invokes the event, the only
other objects that need to consume it are those in row 1 and those in column
2. Sending the notification to other objects would be a waste of CPU.

Is there an "approved" / efficient way to cause only those objects in row 1
and column 2 to receive the event notification? I've looked but just don't
see (or don't recognize) such a thing in the documentation...

Thanks in advance.
Dec 23 '05 #1
8 1346
Pete <pb*@nospam.nospam> wrote:
Assume I have an n by n matrix of identical objects, each of which can both
invoke and consume event A. If, say, obect[1,2] invokes the event, the only
other objects that need to consume it are those in row 1 and those in column
2. Sending the notification to other objects would be a waste of CPU.

Is there an "approved" / efficient way to cause only those objects in row 1
and column 2 to receive the event notification? I've looked but just don't
see (or don't recognize) such a thing in the documentation...


Does the object itself know its position and the objects in the other
positions?

I must say, it's not something I've encountered a need for before...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 23 '05 #2
Hi,

If this event is only handled by certain object, you only need to add the
delegate to the event handler of the single object.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Dec 24 '05 #3
Sorry for the top posting.

If necessary, the objects can be made aware of their own position in the
matrix and can be told about other objects and their locations (all of which
are fixed). It would be better, though, if each object could remain
insensitive to context - to be able to fire the event and to have some
higher level entity route that event as required.

The problem I'm trying to solve is somewhat analogous to the Eight Queens
problem in chess. If I place a rook on a particular square (i.e. a
particular object becomes occupied), I'd like the other squares (objects) on
that rank and file to know that they're under attack. The newly occupied
square needn't care which other squares are under attack nor does the
attacked square care from where the attack comes.

In my case, I'm trying to build a Su Doku solver. In Su Doku, each square in
the matrix can potentially have one of nine values (1 through 9) and once
the value of a square is fixed, no other square on that rank or file can
have the same value. The idea is that if the value of square[m, n] becomes
fixed (e.g., it's known to be X), it would fire an event to be consumed by
the other squares on that rank or file, telling them to remove X from their
list of potential values. If that causes the value of the consuming cell to
become fixed, the consuming cell would fire off it's own similar event to
squares on it's rank and file.

I understand there are plenty of ways to do this depth-first search. I just
wondered if there was a way to use the event mechanism to get that for free.
(And, also, because it would be kind-of interesting to try.)
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Pete <pb*@nospam.nospam> wrote:
Assume I have an n by n matrix of identical objects, each of which can
both
invoke and consume event A. If, say, obect[1,2] invokes the event, the
only
other objects that need to consume it are those in row 1 and those in
column
2. Sending the notification to other objects would be a waste of CPU.

Is there an "approved" / efficient way to cause only those objects in row
1
and column 2 to receive the event notification? I've looked but just
don't
see (or don't recognize) such a thing in the documentation...


Does the object itself know its position and the objects in the other
positions?

I must say, it's not something I've encountered a need for before...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 24 '05 #4

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Pete <pb*@nospam.nospam> wrote:
Assume I have an n by n matrix of identical objects, each of which can
both
invoke and consume event A. If, say, obect[1,2] invokes the event, the
only
other objects that need to consume it are those in row 1 and those in
column
2. Sending the notification to other objects would be a waste of CPU.

Is there an "approved" / efficient way to cause only those objects in row
1
and column 2 to receive the event notification? I've looked but just
don't
see (or don't recognize) such a thing in the documentation...


Does the object itself know its position and the objects in the other
positions?

I must say, it's not something I've encountered a need for before...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


I suppose I could restate the problem for greater clarity.

Assume I have a form with two buttons, exactly one of which should be
enabled at any instant. The traditional way would be to have the form
consume the Clicked event for both buttons and to have the event handler for
each button set the Enabled property of the other button to False. I'm sure,
also, that one could set things up so that the two buttons could mutually
consume each others Clicked events, taking the form out of the mix
altogether.

But both of those approaches get a bit tedious when one introduces 81
buttons and each button has a different set of event trading partners. It
would be way cool if it were possible for, say, a single event handler to
trap the Clicked events for all buttons and, then, re-route those events (as
events, unchanged) by simply iterating over some data structure that
captures the inter-relationships between buttons.

It would be something like having a generic event (i.e., "some button,
somewhere has been clicked") but, then, only the buttons that need to know -
based on some higher-level(perhaps dynamically changing) criteria - would be
notified of that event.
Dec 24 '05 #5
Pete <pb*@nospam.nospam> wrote:
Sorry for the top posting.
No problem - although I must say I'm intrigued as to why you apologised
rather than not top posting :)
If necessary, the objects can be made aware of their own position in the
matrix and can be told about other objects and their locations (all of which
are fixed). It would be better, though, if each object could remain
insensitive to context - to be able to fire the event and to have some
higher level entity route that event as required.


Well, here's an alternative way - make each of the squares expose an
event, and make each square subscribe to the events it's interested in.
So each square on the top row would subscribe to the "changed" event of
each of the other squares on the top row, etc.

The "routing" would be done once, at startup - and then you'd just fire
the event. That's the only way I can see of doing it without the square
being aware of its own position. (There may be ways I can't see, of
course :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 24 '05 #6
Pete <pb*@nospam.nospam> wrote:
I suppose I could restate the problem for greater clarity.

Assume I have a form with two buttons, exactly one of which should be
enabled at any instant. The traditional way would be to have the form
consume the Clicked event for both buttons and to have the event handler for
each button set the Enabled property of the other button to False. I'm sure,
also, that one could set things up so that the two buttons could mutually
consume each others Clicked events, taking the form out of the mix
altogether.

But both of those approaches get a bit tedious when one introduces 81
buttons and each button has a different set of event trading partners.
Surely it only gets tedious when you need to wire up the events
manually. There's no need for that. For instance, you could have code
like this:
using System;

public class Square
{
const int GridSize = 9;

public event EventHandler Changed;

public static void Main()
{
// Create all the squares
Square[,] grid = new Square[GridSize,GridSize];

for (int i=0; i < GridSize; i++)
{
for (int j=0; j < GridSize; j++)
{
grid[i,j] = new Square();
}
}

// Wire up all the events
for (int i=0; i < GridSize; i++)
{
for (int j=0; j < GridSize; j++)
{
// Other squares in the same row and column
// should subscribe
for (int k=0; k < GridSize; k++)
{
if (k != i)
{
grid[i,j].Changed += new EventHandler
(grid[k,j].ChangeHandler);
}
if (k != j)
{
grid[i,j].Changed += new EventHandler
(grid[i,k].ChangeHandler);
}
}
}
}
}

public void ChangeHandler(object sender, EventArgs e)
{
// Do stuff here
}
}
It would be way cool if it were possible for, say, a single event handler to
trap the Clicked events for all buttons and, then, re-route those events (as
events, unchanged) by simply iterating over some data structure that
captures the inter-relationships between buttons.
It would have to know which location had changed though. Either the
square has to know, and tell the event handler that it was that square
(which it would normally do with the "sender" argument), or the event
handler would need to look it up to find the right square.
It would be something like having a generic event (i.e., "some button,
somewhere has been clicked") but, then, only the buttons that need to know -
based on some higher-level(perhaps dynamically changing) criteria - would be
notified of that event.


As I say though, you still need the knowledge of what's been clicked
*somewhere*.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 24 '05 #7

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
Pete <pb*@nospam.nospam> wrote:
I suppose I could restate the problem for greater clarity.

Assume I have a form with two buttons, exactly one of which should be
enabled at any instant. The traditional way would be to have the form
consume the Clicked event for both buttons and to have the event handler
for
each button set the Enabled property of the other button to False. I'm
sure,
also, that one could set things up so that the two buttons could mutually
consume each others Clicked events, taking the form out of the mix
altogether.

But both of those approaches get a bit tedious when one introduces 81
buttons and each button has a different set of event trading partners.


Surely it only gets tedious when you need to wire up the events
manually. There's no need for that. For instance, you could have code
like this:
using System;

public class Square
{
const int GridSize = 9;

public event EventHandler Changed;

public static void Main()
{
// Create all the squares
Square[,] grid = new Square[GridSize,GridSize];

for (int i=0; i < GridSize; i++)
{
for (int j=0; j < GridSize; j++)
{
grid[i,j] = new Square();
}
}

// Wire up all the events
for (int i=0; i < GridSize; i++)
{
for (int j=0; j < GridSize; j++)
{
// Other squares in the same row and column
// should subscribe
for (int k=0; k < GridSize; k++)
{
if (k != i)
{
grid[i,j].Changed += new EventHandler
(grid[k,j].ChangeHandler);
}
if (k != j)
{
grid[i,j].Changed += new EventHandler
(grid[i,k].ChangeHandler);
}
}
}
}
}

public void ChangeHandler(object sender, EventArgs e)
{
// Do stuff here
}
}
It would be way cool if it were possible for, say, a single event handler
to
trap the Clicked events for all buttons and, then, re-route those events
(as
events, unchanged) by simply iterating over some data structure that
captures the inter-relationships between buttons.


It would have to know which location had changed though. Either the
square has to know, and tell the event handler that it was that square
(which it would normally do with the "sender" argument), or the event
handler would need to look it up to find the right square.
It would be something like having a generic event (i.e., "some button,
somewhere has been clicked") but, then, only the buttons that need to
know -
based on some higher-level(perhaps dynamically changing) criteria - would
be
notified of that event.


As I say though, you still need the knowledge of what's been clicked
*somewhere*.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Yeah! You're right on all points. I suppose I was just thinking it might be
nice to have, in addition to the (sender, eventArgs) semantics, something
along the lines of (receiver, eventArgs) and/or (sender, receiver,
eventArgs) semantics also available. Might not be handy all the time and it
can be simutated by attaching and detaching event handlers but, well, you
know...

Thanks. Happy Holidays.
Dec 24 '05 #8
Pete <pb*@nospam.nospam> wrote:
Yeah! You're right on all points. I suppose I was just thinking it might be
nice to have, in addition to the (sender, eventArgs) semantics, something
along the lines of (receiver, eventArgs) and/or (sender, receiver,
eventArgs) semantics also available. Might not be handy all the time and it
can be simutated by attaching and detaching event handlers but, well, you
know...
Hmm. One of the nice things about the current eventing model is that
the object raising the event doesn't need to know *anything* about
what's handling it - just that there's a delegate of the right type for
it to invoke. I think when you start specifying receivers, you lose a
lot of that elegance.

Of course, you can create any delegate you want and use it for your
event type - in your case you could create your own delegate which
included the position within the grid of the sender.
Thanks. Happy Holidays.


You too.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 24 '05 #9

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

Similar topics

0
by: Andy Read | last post by:
Hello all, I have the requirement to produce source code that produces an object hierarchy. Example: Root | Folder 1
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
0
by: Nicholas Beenham | last post by:
Hi all, I'm having problems with a udpclient with multicasting and then waiting for a response and if none arrives closes after a few seconds. I have the client multicasting fine but am having...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
0
by: gregory_may | last post by:
I posted this in the dotnet.framework group with no responce yet, maybe someone in these groups can point me in the right direction? Or maybe I need to use something already in .Net to get an IGMP...
0
by: POgletree | last post by:
I need to set up a small client/server or, best solution, a peer-to-peer system to swap data strings between wide spread users. I've looked at IP multicasting and it seems like a reasonable...
9
by: Sayudh27 | last post by:
Hi all, I am a relatively new programmer in C++...I need to write a code that performs multicasting as well as returns the data-packets in a decompressed form.Data-receipt seems to work...
1
by: Nick | last post by:
Does any one have a simple wcf of udp multicating other than the one posted here http://wcf.netfx3.com/files/folders/transport_channels/entry5235.aspx I would like a program with just the basics...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.