I have a simple WPF application with a button, when the button clicked it calls to a method that start a process - cmd command, the cmd command can take 1 minute. The problem is, at this time (when the process wait for exit and get a result) the application is stuck.
My code in the UI is:
private void Button_Click(object sender, RoutedEventArgs e)
{
// the method Import take 1 minute
var result = Helpers.Import();
if (result)
{
MessageBox.Show("Sucess", "Sucess");
}
else
{
MessageBox.Show("Error", "Error",);
}
}
My code in the BL is:
public static bool Import()
{
ProcessStartInfo info = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\witadmin.exe", arguments);
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process p = Process.Start(info);
p.WaitForExit();
if (p.ExitCode == 0)
{
return true;
}
else
{
return false;
}
}
When the application waits for the exit code the UI is stuck.
How can I solve it?