Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#/.Net equivalent of NSNotification

I'm an Objective-C developer porting an application to the .Net world. In my Obj-C application, I use NSNotification objects to communicate asynchronously between a handful of objects. Is there some way to do something similar in the .Net world (more specifically, using the C# language)? The fundamental approach is that one object posts a notification that one or more objects listen for.

There's probably an obvious way of doing this, but I haven't found it yet...

like image 503
cjkarr Avatar asked Jan 03 '09 23:01

cjkarr


1 Answers

Using Delegates in C# or VB.NET is the equivalent language integrated feature. You can create events by defining or using a predefined Delegate to define the "notification" that can be published and subscribed to. Then define an event on a class that you can subscribe to and raise. The MSDN documentation has a good overview once you find it here. A good example is here.

like image 141
Scott Willeke Avatar answered Sep 20 '22 17:09

Scott Willeke