static void bo_Publish(BusinessObject sender, EventArgs args) { if (sender is BusinessObject1) { BusinessObject1 bo1 = (BusinessObject1)sender; BusinessObject1.PublishBusinessObject1EventArgs args1 = (BusinessObject1.PublishBusinessObject1EventArgs)args; Console.WriteLine("Updated {0} to {1}", args1.oldValue, bo1.Value); } }
static void bo_Publish2(BusinessObject sender, EventArgs args) { if (sender is BusinessObject1) { BusinessObject1 bo1 = (BusinessObject1)sender; BusinessObject1.PublishBusinessObject1EventArgs args1 = (BusinessObject1.PublishBusinessObject1EventArgs)args; Console.WriteLine("Second handler detected updated of {0} to {1}", args1.oldValue, bo1.Value); } }
static void Main(string[] args) { // Create some business objects and ask them to initialize // themselves. // var bo1 = new BusinessObject1(); var bo2 = new BusinessObject2(); bo1.Fill(); bo2.Fill(); }
static void Main(string[] args) { BusinessObject1 bo = new BusinessObject1("First Value"); // Subscribe bo.Publish += new BusinessObject.PublishObject(bo_Publish); bo.Update("Second Value"); // UnSubscribe bo.Publish -= new BusinessObject.PublishObject(bo_Publish); bo.Update("Third Value"); // Subscribe multiple bo.Publish += new BusinessObject.PublishObject(bo_Publish); bo.Publish += new BusinessObject.PublishObject(bo_Publish2); bo.Update("Fourth Value"); // UnregisterAllMessages bo.UnsubcribeAll(); bo.Update("Fifth Value"); }