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. C#
  4. Global Event Handler?

Global Event Handler?

Scheduled Pinned Locked Moved C#
databasealgorithmshelptutorialquestion
5 Posts 4 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.
  • M Offline
    M Offline
    musefan
    wrote on last edited by
    #1

    Hi all, Im not quite sure what i want to use for my problem so i thought maybe somebody out there has a good solution. My situation is that i have a user control that, for example, displays a list of database entries such as messages. This control can be present in multiple forms that esentially need to be syncrhonised. For example, if an entry is added, edited or deleted in one control, all other controls need to be notified of this and know to look for updates. As my subject may suggest I have thought of a global event that all instances can listen for, but have not tried yet as i dont know if this is a good option. Does anybody know of any 'best practice' solutions for this situation? I usually find my answers with google, but in this instance im not even sure what im searching for. Thanks

    Life goes very fast. Tomorrow, today is already yesterday.

    0 D D 3 Replies Last reply
    0
    • M musefan

      Hi all, Im not quite sure what i want to use for my problem so i thought maybe somebody out there has a good solution. My situation is that i have a user control that, for example, displays a list of database entries such as messages. This control can be present in multiple forms that esentially need to be syncrhonised. For example, if an entry is added, edited or deleted in one control, all other controls need to be notified of this and know to look for updates. As my subject may suggest I have thought of a global event that all instances can listen for, but have not tried yet as i dont know if this is a good option. Does anybody know of any 'best practice' solutions for this situation? I usually find my answers with google, but in this instance im not even sure what im searching for. Thanks

      Life goes very fast. Tomorrow, today is already yesterday.

      0 Offline
      0 Offline
      0x3c0
      wrote on last edited by
      #2

      If all the events have a similar signature, Delegate.CreateDelegate (starting with .Net v2.0, it supports covariance) and EventInfo.AddEventHandler should help. However, if you absolutely must use methods with completely different method signatures, then try this approach

      1 Reply Last reply
      0
      • M musefan

        Hi all, Im not quite sure what i want to use for my problem so i thought maybe somebody out there has a good solution. My situation is that i have a user control that, for example, displays a list of database entries such as messages. This control can be present in multiple forms that esentially need to be syncrhonised. For example, if an entry is added, edited or deleted in one control, all other controls need to be notified of this and know to look for updates. As my subject may suggest I have thought of a global event that all instances can listen for, but have not tried yet as i dont know if this is a good option. Does anybody know of any 'best practice' solutions for this situation? I usually find my answers with google, but in this instance im not even sure what im searching for. Thanks

        Life goes very fast. Tomorrow, today is already yesterday.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You don't make this a "global" event. This would probably be an event exposed by a singleton data store you create. An event can have multiple subscribers, but since you're sharing data acrossed multiple instances of your control, it would suggest using a central data store to back all instances of the control.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        M 1 Reply Last reply
        0
        • M musefan

          Hi all, Im not quite sure what i want to use for my problem so i thought maybe somebody out there has a good solution. My situation is that i have a user control that, for example, displays a list of database entries such as messages. This control can be present in multiple forms that esentially need to be syncrhonised. For example, if an entry is added, edited or deleted in one control, all other controls need to be notified of this and know to look for updates. As my subject may suggest I have thought of a global event that all instances can listen for, but have not tried yet as i dont know if this is a good option. Does anybody know of any 'best practice' solutions for this situation? I usually find my answers with google, but in this instance im not even sure what im searching for. Thanks

          Life goes very fast. Tomorrow, today is already yesterday.

          D Offline
          D Offline
          Dragonfly_Lee
          wrote on last edited by
          #4

          Agree with Dave. In your case, no need to create a "complex" global event manager. Just update the UI when you modify the data. Simplicity is always good. :-D

          :) I Love KongFu~

          1 Reply Last reply
          0
          • D Dave Kreskowiak

            You don't make this a "global" event. This would probably be an event exposed by a singleton data store you create. An event can have multiple subscribers, but since you're sharing data acrossed multiple instances of your control, it would suggest using a central data store to back all instances of the control.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            M Offline
            M Offline
            musefan
            wrote on last edited by
            #5

            thanks for your suggestion Dave, i will take a look into it

            Life goes very fast. Tomorrow, today is already yesterday.

            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