using System; using System.Diagnostics; using System.Threading.Tasks; public static class DisplayFusionFunction { static Task<int> Test() { var tcs = new TaskCompletionSource<int>(); var process = new Process { StartInfo = { FileName = "timeout", Arguments = "1" }, EnableRaisingEvents = true }; process.Exited += (sender, args) => { tcs.SetResult(process.ExitCode); process.Dispose(); }; try { process.Start(); } catch { return Task.FromResult(-1); } return tcs.Task; } public static async void Run(IntPtr windowHandle) { await Test(); System.Windows.Forms.MessageBox.Show("Successfully completed!"); } }