Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Shared members raising events

Shared members raising events

Scheduled Pinned Locked Moved Visual Basic
helpc++
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cnurse
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • C cnurse

      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

      C Offline
      C Offline
      cnurse
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups