static void Main(string[] args) { // we will create our instance Shipment myItem = new Shipment(); // we need to add the delegate event to new object myItem.OnPopUpWindowOccurred += new Shipment.PopupHandler(ShowUserMessage); // we assumed that the item has been just shipped and // we are assigning a tracking number to it. // myItem.TrackingNumber = myItem.IswindowExists() ? "Yes" : "No"; // The common procedure to see what is going on the // console screen Thread t2 = new Thread(delegate() { checkasync(myItem); } ); t2.Start(); for (int i=0; i< 100 ; i++) { Console.WriteLine("Exeuctelin line " + i); System.Threading.Thread.Sleep(1000); } Console.Read(); }
static void checkasync(Shipment spp) { bool ck = true; while (ck == true) { spp.TrackingNumber = spp.IswindowExists() ? "Yes" : "No"; } // spp.TrackingNumber => }
static void ShowUserMessage(object a, ShipArgs e) { Console.WriteLine(e.Message); Shipment myItem2 = new Shipment(); myItem2.closepopup(); }