Click here to Skip to main content
11,932,103 members (56,945 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


18 bookmarked

C# NotificationCenter

, 10 Aug 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
A NotificationCenterManager object (or simply, notification center) provides a mechanism for broadcasting information within a program.


A NotificationCenterManager object (or simply, notification center) provides a mechanism for broadcasting information within a program. A NotificationCenterManager object is essentially a notification dispatch table.

Objects register with a notification center to receive notifications (Notification objects) using the AddObserver method. Each invocation of this method specifies a set of notifications. Therefore, objects may register as observers of different notification sets by calling these methods several times.

Each running C# program has a default notification center. You typically don’t create your own. A NotificationCenterManager object can deliver notifications only within a single program.


There can be a few conflicting techniques to solve a problem. Any can be chosen to achieve your goal. However, sometimes I want to know what can fit better for this and that. One of those conflicting techniques are Events (using delegates) and Notification in a same process or a task. An Event is to have an object that fires an event when it's happened. Notification is to send an alarm to a monitoring object if something happens. For both, a monitoring object should be registered to some entities. So, mostly they are very similar.

But Notification is free form to be connected to another object. For example the mains form can send a notification to a User Control inside in another User Control without no connection between them.

Using the code

First of all create a NotificationCenterManager object. NotificationCenterManager uses the Singleton pattern so get an instance like his:

using NotificationCenter;
NotificationCenterManager notificationCenterManager = NotificationCenterManager.Instance;

Next use the NotificationCenterManager instance to register to Notification with the method AddObserver:

public class Observer
    public Observer()
        NotificationCenterManager notificationCenterManager = NotificationCenterManager.Instance;
           "SomeNotification");// register to Notification "SomeNotification".
    private void OnNotification(Notification p_notification)

Next use the NotificationCenterManager instance to post  a Notification with "Empty Message" with the method PostNotification:

NotificationCenterManager.Instance.PostNotification("SomeNotification ");
// Post Notification "SomeNotification".

Use the NotificationCenterManager instance to post a Notification with "Notification Message" with the method PostNotification:

Notification notification=new Notification(this,"Some Object With Message");
NotificationCenterManager.Instance.PostNotification("SomeNotification", notification);
// Post Notification "SomeNotification".

To remove matching entries from the receiver’s dispatch table use the NotificationCenterManager instance to unregister from Notification with the method RemoveObserver:

NotificationCenterManager.Instance.RemoveObserver(OnNotification, "SomeNotification");
// OnNotification is the delegate to the Observer.


10/08/12: Initial post.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

One Man Crew
Software Developer (Senior)
Israel Israel
Software Engineer with interest in .Net, C#, PHP ,Objective-c ,Java,JavaScript,HTML5

Programming since 1990(write my first QBasic program).
Web programming since 1995.
Started writing "hacks" at 14.
Build my First BBS at 14(through college BBSes) pre-'internet' at this point.
Assembly language "hacking" at 17.


Objective C

Currently studying Computer vision,Image processing .

You may also be interested in...

Comments and Discussions

QuestionError fire Notification Pin
Member 1069907211-Apr-14 15:48
memberMember 1069907211-Apr-14 15:48 
AnswerRe: Error fire Notification Pin
One Man Crew19-Apr-14 10:07
memberOne Man Crew19-Apr-14 10:07 
GeneralVery cool Pin
maxvale17-Dec-12 16:13
membermaxvale17-Dec-12 16:13 
QuestioniOS NSNotificationCenter Pin
lauhw200014-Oct-12 19:02
memberlauhw200014-Oct-12 19:02 
AnswerRe: iOS NSNotificationCenter Pin
One Man Crew15-Oct-12 4:39
memberOne Man Crew15-Oct-12 4:39 
GeneralMy vote of 5 Pin
Dave Hickson11-Aug-12 22:28
memberDave Hickson11-Aug-12 22:28 
GeneralRe: My vote of 5 Pin
onemancre11-Aug-12 22:36
memberonemancre11-Aug-12 22:36 
Thanks for the feedback. Smile | :)
GeneralMy vote of 3 Pin
Klaus Luedenscheidt10-Aug-12 18:35
memberKlaus Luedenscheidt10-Aug-12 18:35 
GeneralRe: My vote of 3 Pin
onemancre11-Aug-12 8:44
memberonemancre11-Aug-12 8:44 
GeneralRe: My vote of 3 Pin
Klaus Luedenscheidt11-Aug-12 19:02
memberKlaus Luedenscheidt11-Aug-12 19:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151126.1 | Last Updated 10 Aug 2012
Article Copyright 2012 by One Man Crew
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid