I'm coding a c# console app that connects to vpn and after it's connected it sends an http request to a web server. The problem is that I can't know the exact time when vpn is connected. Because of this the app sends the http request before connected to vpn and this results in timed out for vpn, then it takes a much longer time to recover.
Process.Start("vpn-connect.bat");
Thread.Sleep(5000);
//Send https request
vpn-connect.bat starts the vpn connection but it doesn't return anything to tell me if connection succeeded or not. So I have to rely on Thread.Sleep to wait before sending http request and is a bad solution cause it's failing very often.
Is there any way to replace Thread.Sleep with something that's accurate and it tells the app when vpn is finally connected?