Create a singleton class, which your forms will all share. The forms can register/deregister for events as they come up/down.
Since the PhidgetBridge object isn't owned by your forms, you will need to handle Invoke yourself if you need to access the form directly from and Phidget events.
For example:
Code: Select all
public class BridgeSingleton
{
private static PhidgetBridge instance;
private BridgeSingleton() {}
public static PhidgetBridge Bridge
{
get
{
if (instance == null)
{
instance = new PhidgetBridge();
instance.open();
instance.waitForAttachement(500);
}
return instance;
}
}
}
Then, in your forms:
Code: Select all
BridgeSingleton.Bridge.BridgeData += BridgeDataEventHandler;
Note: this is pretty basic/untested. You would probably want to implement some sort of static connect function so you can handle waitForAttachement timeouts, or don't waitForAttachement, but handle attach/detach events, etc...
-Patrick