Hello guys, share my solution.
Hope this helps !
Mongodump and Mongorestore are applications, not MongoDB commands which is why i would have to run the executable on another thread for not freeze the UI if the operation fail.
Using Mongodump:
Task.Run(() =>
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
//Important is that the argument begins with /C otherwise it won't work.
startInfo.Arguments = @"/C mongodump --db shop --out \backup\mongo\";
process.StartInfo = startInfo;
process.Start();
while (!process.HasExited) ;
if (process.ExitCode == 0)
{
MessageBox.Show("Backup OK !");
}
else
{
MessageBox.Show($"Backup fail ! Exit code: {process.ExitCode}");
}
});