public void StartProcess() { var data = new ProcessEventArgs(); try { Console.WriteLine("Process Started!"); data.StartTime = DateTime.Now; //Delay 5 seconds Thread.Sleep(5000); data.IsSuccessful = true; data.CompletionTime = DateTime.Now; OnProcessCompleted(data); } catch { data.IsSuccessful = false; data.CompletionTime = DateTime.Now; OnProcessCompleted(data); } }
protected virtual void OnProcessCompleted(ProcessEventArgs e) { ProcessCompleted?.Invoke(this, e); }
// event handler public static void bl_ProcessCompleted(object sender, ProcessEventArgs e) { Console.WriteLine("Process " + (e.IsSuccessful ? "Completed Successfully" : "failed")); Console.WriteLine("Completion Time: " + e.CompletionTime); }