How can I pause between two commands
Clash Royale CLAN TAG#URR8PPP
How can I pause between two commands
I would like to pause in between two dos commands that stop and start a service.
Here is the code:
( code was borrowed from How can a windows service programmatically restart itself? )
Process proc = new Process();
ProcessStartInfo psi = New ProcessStartInfo();
psi.CreateNoWindow = true;
psi.FileName = "cmd.exe";
psi.Arguments = "/C net stop YOURSERVICENAMEHERE && net start YOURSERVICENAMEHERE";
psi.LoadUserProfile = false;
psi.UseShellExecute = false;
psi.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo = psi;
proc.Start();
basically, I want to put a 'pause' in between the stop and start:
psi.Arguments = "/C net stop YOURSERVICENAMEHERE && timeout /t 10 /nobreak && net start YOURSERVICENAMEHERE"
Why don't you simply stop the service, use the many sleeping methods available in NET and then start the second service? Is it mandatory to do on a single command line?
– Steve
Aug 10 at 19:22
it's the same service that is stopped and started... and once the service is stopped... it can't be started again without the second "start" command... (this is INTERNAL to the service )
– user3174075
Aug 10 at 19:24
1 Answer
1
There are ways to do this in .NET using the ServiceController class and avoiding any interaction with the shell.
You can find those here:MSDN ServiceController
If you'd prefer to invoke a process through the CMD, you can create two separate processes and call either Thread.Sleep(milliseconds) or Task.Delay(milliseconds) to wait. Additionally, make sure that after you start your process, call the .WaitForExit() method so that the process completes before moving on.
Personally, I recommend using ServiceController as it uses all .NET components rather than relying on the shell.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
not any more...
– user3174075
Aug 10 at 19:19