Reputation: 61
I've wrote an wpf app, from which i would like to call 20 external processes, after all processes are finished wpf app should continue normal execution. I succeded in calling those processes and they work just fine. They receive parameters from wpf, but afterwards wpf gui is not showing and qouted message is showed in console.
When I call process from the following code once or twice it works well, but after few times it stops working. I already tried commented lines
string arguments = "thumbnail " + input + " " + output.LocalPath;
Process p = Process.Start(videoToolPath, arguments);
while(!p.HasExited)
{
Thread.Sleep(1000);
}
//p.Dispose();
//p.Kill();
//p.Close();
Console:
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'E:\Projects\MediaGUI\newVSProject\VJProject\VJProject\bin\Debug\VJProject.vshost.exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35\PresentationCore.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 0x1ee4 has exited with code 259 (0x103).
The thread 0x1e18 has exited with code 259 (0x103).
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'E:\Projects\MediaGUI\newVSProject\VJProject\VJProject\bin\Debug\VJProject.exe'. Symbols loaded.
Step into: Stepping over non-user code 'VJProject.App..ctor'
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Step into: Stepping over non-user code 'VJProject.App.Main'
Step into: Stepping over non-user code 'VJProject.App.InitializeComponent'
The thread 0x26d8 has exited with code 259 (0x103).
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero2\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero2.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXml\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXml.dll'. Cannot find or open the PDB file.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXmlLinq\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXmlLinq.dll'. Cannot find or open the PDB file.
'VJProject.vshost.exe' (CLR v4.0.30319: VJProject.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\UIAutomationTypes\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationTypes.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Upvotes: 0
Views: 245
Reputation: 15772
You want to do this asynchronously. The easiest way to do this is with the async
await
pattern. The bad news is that Process
does not support Task async.
public Task ProcessVideo(string input, xxx output)
{
string arguments = "thumbnail " + input + " " + output.LocalPath;
Process p = Process.Start(videoToolPath, arguments);
var tcs = new TaskCompletionSource<object>();
p.Exited += (o, e) =>
{
if(p.ExitCode == 0)
{
tcs.SetResult(null);
}
else
{
tcs.SetException(someException);
}
p.Dispose();
}
return tcs.Task;
}
//Then call it by
var listOfFilesToProcess = new List<string>(){ ... };
await Task.WhenAll(listOfFilesToProcess.Select(file => ProcessVideo(file, output));
Upvotes: 1
Reputation: 448
If you just want to wait for the external program to exit:
var process = Process.Start(...);
process.WaitForExit();
int code = process.ExitCode;
if (code != 0)
{
//failure
}
else
{
//success
}
(Don't do this inside your UI-Thread, it will block it)
Upvotes: 1