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

  • Thread starter Thread starter Tom
  • Start date Start date
T

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
 
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.
 
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.
 
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.
 
Back
Top