35
1
using System;
2
3
public class Program
4
{
5
public static void Main()
6
{
7
ProcessBusinessLogic bl = new ProcessBusinessLogic();
8
bl.ProcessCompleted += bl_ProcessCompleted; // register with an event
9
bl.StartProcess();
10
}
11
12
// event handler
13
public static void bl_ProcessCompleted(object sender, EventArgs e)
14
{
15
Console.WriteLine("Process Completed!");
16
}
17
}
18
19
public class ProcessBusinessLogic
20
{
21
public event EventHandler ProcessCompleted; // event
22
23
public void StartProcess()
24
{
25
Console.WriteLine("Process Started!");
26
// some code here..
27
OnProcessCompleted(EventArgs.Empty);
28
}
29
30
31
protected virtual void OnProcessCompleted(EventArgs e)
32
{
33
ProcessCompleted?.Invoke(this, e);
34
}
35
}
Cached Result