| 1 | # Delegates and Events |
| 2 | |
| 3 | The WinRT delegates project to normal C# delegates and are consumed as normal C# events. |
| 4 | |
| 5 | ```csharp |
| 6 | public delegate void SessionTerminationHandler(SessionTerminationReason reason); |
| 7 | public delegate void ProcessCrashHandler(ProcessCrashInformation information); |
| 8 | public delegate void ProcessOutputHandler(byte[] data); |
| 9 | public delegate void ProcessExitHandler(int exitCode); |
| 10 | ``` |
| 11 | |
| 12 | Typical event usage: |
| 13 | |
| 14 | ```csharp |
| 15 | using System.Text; |
| 16 | |
| 17 | session.Terminated += reason => Console.WriteLine($"Session ended: {reason}"); |
| 18 | session.ProcessCrashed += info => Console.WriteLine($"Process crashed: {info.ProcessName} ({info.Pid})"); |
| 19 | container.InitProcess.OutputReceived += data => Console.Write(Encoding.UTF8.GetString(data)); |
| 20 | container.InitProcess.ErrorReceived += data => Console.Error.Write(Encoding.UTF8.GetString(data)); |
| 21 | container.InitProcess.Exited += code => Console.WriteLine($"Init exited: {code}"); |
| 22 | ``` |
| 23 | |
| 24 | --- |