I run an update process from my c# wpf program like this:
Process sql = Process.Start("sqlcmd.exe", param);
sql.WaitForExit(1200000);
The variable param is build from user input in the ui, here is a example:
sqlcmd.exe -S .\SQLEXPRESS -d mydatabase -v db_src = "db\file.bak" -i db\update.sql -o "\log\log_update.txt"
Now the black cmd window opens and runs for a while (1-5 minutes). On some machines the white curos blinks. What I want is that something like "Please wait... & "
is printed on the cmd window.
I've tried different approaces but the sqlmd erases everything. Like putting a echo Please wait...
in front of param.
Displaying something in the c# program is also difficult because while the process runs, the program is frozen. But if anyone knows a solution which makes it possible to display a message in the program this would also be fine.
Using .WaitForExit()
blocks your current application thread. Instead you should just start the process in the background, and wait for the Exited
event.
To quote MSDN - see the remarks:
WaitForExit() makes the current thread wait until the associated process terminates. It should be called after all other methods are called on the process. To avoid blocking the current thread, use the Exited event.
If your thread isn't blocked you can write progress/status messages that'll actually appear.