Global Event Handler?
-
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.
-
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.
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
-
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.
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 -
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.
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~
-
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