Shared members raising events
-
This seems a real tricky one. I want a class which is a single instance. So what I did was make all its members shared and they in turn are accessed by property gets/sets as you would expect. I then want a shared timer, so no matter how many other objects have a reference to my "singleton" class they all receive a polled event which emanates from the one timer. I want a timer in the singleton class that polls all interested parties at one tick every 100 ms. Problem is because the timer is shared... Shared mTimer as New Timer The event that the Timer class raises is shared... Shared Sub mTimer_Tick... If I try and do this... Shared Sub mTimer_Tick... RaiseEvent MyTimerEvent end sub I have to write.... Shared event MyTimerEvent But then in my object which utilises this class.... Dim WithEvents mObject as MySingletonObject This fails because it says there are no events that can be raised on MySingletonObject which is bull. So this is something to do with have shared members that raise events that you in turn want to pass onto to a whole heap of other objects, and I can't find a way to do it. If I was to fall back to C++, I'd start sending Window messages, like the fix for having a timer on one thread which polls a window on another thread to say the timer has fired, remember that one! Ah well, any corrections to my technique will cause tears and tantrums, but I will try and listen hahahaha Thx! Nursey
-
This seems a real tricky one. I want a class which is a single instance. So what I did was make all its members shared and they in turn are accessed by property gets/sets as you would expect. I then want a shared timer, so no matter how many other objects have a reference to my "singleton" class they all receive a polled event which emanates from the one timer. I want a timer in the singleton class that polls all interested parties at one tick every 100 ms. Problem is because the timer is shared... Shared mTimer as New Timer The event that the Timer class raises is shared... Shared Sub mTimer_Tick... If I try and do this... Shared Sub mTimer_Tick... RaiseEvent MyTimerEvent end sub I have to write.... Shared event MyTimerEvent But then in my object which utilises this class.... Dim WithEvents mObject as MySingletonObject This fails because it says there are no events that can be raised on MySingletonObject which is bull. So this is something to do with have shared members that raise events that you in turn want to pass onto to a whole heap of other objects, and I can't find a way to do it. If I was to fall back to C++, I'd start sending Window messages, like the fix for having a timer on one thread which polls a window on another thread to say the timer has fired, remember that one! Ah well, any corrections to my technique will cause tears and tantrums, but I will try and listen hahahaha Thx! Nursey
Dear all, I've now seen the error of my ways and produced a more elegant way, and adopted a more technically correct approach from an OO point of view. I have a polling class and a polled object interface which people can implement. They register their objects with the "poller" and it polls all registered object periodically, so I have a single timer object which can trigger events in many objects which I think gives me basically limitless resource, rather than having loads of timers running. This lets me do things like blinking buttons, if you're interested. Anyway, it will all be included in the next release of my XP buttons and docking containers release. Thanks anyway. Nursey