473,503 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Event to receive in multiple objects at the same time - how ?

Tom
Dear experts,

this time my problem is, that I will have objects of 3 different
classes, which all should receive their events without knowing each
other.

In real life the following happens:

I have three fingerprints which are waiting for a finger to be put on
sensor.
As soon as the first fingerprint reckognizes a finger, all the others
should be shutten down.

In code the following happens:

scannerX x = new scannerX();
//Start the wait for finger proc in a thread
x.IsFingerPresent();

scannerY y = new scannerY();
//Start the wait for finger proc in a thread
y.IsFingerPresent();

scannerZ z = new scannerZ();
//Start the wait for finger proc in a thread
z.IsFingerPresent();

//IsFingerPresent does the following:
// System.Threading.Thread t = null;
// t = new Thread(new ThreadStart(this.ScanImage))
// t.Start();

// ScanImage waits for some things to happen and if a finger is
detected,
// it raises an eventproc.

The concrete problem now is:

I can not add an eventhandler of y (scannerY) to z (scannerZ) because
z does not even know that y exists (there is no reference to y).

Is there a way to do something like a global/static eventhandler
which could be used by all objects in my application and could be
raised from anywhere out of my app ?

Thanks for any help !!

Greets

Tom
Nov 16 '05 #1
3 1729
If all the scanner classes look and act the same, why not have a base class, called scanner, derive each scanner from the base class, then call base class event handler, or function.
If thats possible =). (My visual studio is down at the moment)

Good luck.
Steve.

--
Message posted via http://www.dotnetmonster.com
Nov 16 '05 #2
Tom,

Why not have a manager object that the scanners register with? This
object would handle the coordination of shutting down the other scanners
when one detects a fingerprint, or something of that nature. It would most
likely be a singleton or static.

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

"Tom" <ts@ck-de.net> wrote in message
news:2f*************************@posting.google.co m...
Dear experts,

this time my problem is, that I will have objects of 3 different
classes, which all should receive their events without knowing each
other.

In real life the following happens:

I have three fingerprints which are waiting for a finger to be put on
sensor.
As soon as the first fingerprint reckognizes a finger, all the others
should be shutten down.

In code the following happens:

scannerX x = new scannerX();
//Start the wait for finger proc in a thread
x.IsFingerPresent();

scannerY y = new scannerY();
//Start the wait for finger proc in a thread
y.IsFingerPresent();

scannerZ z = new scannerZ();
//Start the wait for finger proc in a thread
z.IsFingerPresent();

//IsFingerPresent does the following:
// System.Threading.Thread t = null;
// t = new Thread(new ThreadStart(this.ScanImage))
// t.Start();

// ScanImage waits for some things to happen and if a finger is
detected,
// it raises an eventproc.

The concrete problem now is:

I can not add an eventhandler of y (scannerY) to z (scannerZ) because
z does not even know that y exists (there is no reference to y).

Is there a way to do something like a global/static eventhandler
which could be used by all objects in my application and could be
raised from anywhere out of my app ?

Thanks for any help !!

Greets

Tom

Nov 16 '05 #3
I'd probably do what Nick suggested, which is have a manager object
orchestrate the shutting down of scanners.

but an alternative would be to have a static event define for scanner that
every scanner will link up to in the instance constructor. the first scanner
recognizes a finger will fire that event to initiate the shutdown of other
scanners. two things to look out for, make sure static event is thread safe
and that scanner should implement the Dispose pattern to unhook itself.
otherwise, all scanners will live as long as the AppDomain once constructed
which is probably a bad thing.

"Tom" wrote:
Dear experts,

this time my problem is, that I will have objects of 3 different
classes, which all should receive their events without knowing each
other.

In real life the following happens:

I have three fingerprints which are waiting for a finger to be put on
sensor.
As soon as the first fingerprint reckognizes a finger, all the others
should be shutten down.

In code the following happens:

scannerX x = new scannerX();
//Start the wait for finger proc in a thread
x.IsFingerPresent();

scannerY y = new scannerY();
//Start the wait for finger proc in a thread
y.IsFingerPresent();

scannerZ z = new scannerZ();
//Start the wait for finger proc in a thread
z.IsFingerPresent();

//IsFingerPresent does the following:
// System.Threading.Thread t = null;
// t = new Thread(new ThreadStart(this.ScanImage))
// t.Start();

// ScanImage waits for some things to happen and if a finger is
detected,
// it raises an eventproc.

The concrete problem now is:

I can not add an eventhandler of y (scannerY) to z (scannerZ) because
z does not even know that y exists (there is no reference to y).

Is there a way to do something like a global/static eventhandler
which could be used by all objects in my application and could be
raised from anywhere out of my app ?

Thanks for any help !!

Greets

Tom

Nov 16 '05 #4

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

Similar topics

10
3561
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
18
2849
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...
21
18650
by: Alo Sarv | last post by:
Hi From what I have understood from various posts in this newsgroup, writing event loops pretty much comes down to this: while (true) { handleEvents(); sleep(1); // or _sleep() or...
1
2529
by: emma middlebrook | last post by:
Hi I want to find out what objects are due to receive an event i.e. those that have added themselves as an event handler via +=. Yes, it's a little pointless perhaps (or can anyone give some...
1
3410
by: Daniel Bass | last post by:
hey guys. overview --------- I'm designing a messaging system that works on the principle of late binding to the I/O objects, depending on the .Net class libraries present in the local folder....
7
2852
by: copx | last post by:
How do you implement an event queue in C? The problem I had is that events needed pointers to the objects they affect and I do not know any way to check if pointers are actually valid in C. The...
4
2981
by: Academic | last post by:
Does it make sense to put this If e.Cancel Then Exit Sub at the beginning of form closing events so if the user cancels the app's exiting in one Closing routine he will not be asked again by...
31
2557
by: Scott M. | last post by:
Am I correct in thinking that because C# doesn't have the "Handles" keyword that VB .NET does, we have to register event delegates manually in C#, whereas in VB .NET using "Handles" takes care of...
27
2086
by: cmdolcet69 | last post by:
Can anyone tell me if its possible to do multiple event args in vb.net?
0
7205
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,...
0
7287
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,...
0
7353
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...
1
7011
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...
0
7468
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...
0
5596
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,...
1
5023
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...
0
3180
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...
0
1521
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 ...

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.