I have created the following code. I supposed it would work, but it doesn't. The await hangs there indefinitely (Exit event is never called).
I'm calling "ping" with no arguments, so it would end almost immediately.
using System;
using System.Diagnostics;
using System.Reactive.Linq;
using System.Threading.Tasks;
namespace ConsoleApp3
{
class Program
{
static async Task Main(string[] args)
{
var process = new Process
{
StartInfo =
{
FileName = "ping",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
},
EnableRaisingEvents = true
};
var obs = Observable.FromEventPattern(handler => process.Exited += handler, handler => process.Exited -= handler);
var started = process.Start();
if (!started)
{
throw new InvalidOperationException("Could not start process: " + process);
}
await obs.FirstAsync();
}
}
}
How can I make it work using IObservable?