A
ashah
Hi everyone,
I am using CreateProcess() in my application and every once in a while
get a native exception while doing so. It isn't very frequent, but
I'm still wondering what might be causing it. I'm including the code
below - any suggestions are appreciated!
Thanks,
Amol
public class LaunchApp
{
public class ProcessInfo
{
public Int32 hProcess;
public Int32 hThread;
public Int32 ProcessID;
public Int32 ThreadID;
}
// CreateProcess PInvoke API
[DllImport("CoreDll.DLL", SetLastError=true)]
private static extern int CreateProcess(
String imageName,
String cmdLine,
IntPtr lpProcessAttributes,
IntPtr lpThreadAttributes,
Int32 boolInheritHandles,
Int32 dwCreationFlags,
IntPtr lpEnvironment,
IntPtr lpszCurrentDir,
byte [] si,
ProcessInfo pi );
public bool CreateProcess( String ExeName, String CmdLine,
ProcessInfo pi )
{
if ( pi == null )
pi = new ProcessInfo();
byte [] si = new byte[128];
return CreateProcess(ExeName, CmdLine, IntPtr.Zero, IntPtr.Zero,
0, 0, IntPtr.Zero, IntPtr.Zero, si, pi) != 0;
}
public AfariaApp()
{
}
/// <summary>
/// Runs the application as a seperate process
/// </summary>
public void Connect(string channelSet)
{
// This is actually read in from a config file
string appPath = "\Program Files\app.exe"; // some path
this.CreateProcess(appPath, "ChannelSet=" + channelSet, null);
}
}
I am using CreateProcess() in my application and every once in a while
get a native exception while doing so. It isn't very frequent, but
I'm still wondering what might be causing it. I'm including the code
below - any suggestions are appreciated!
Thanks,
Amol
public class LaunchApp
{
public class ProcessInfo
{
public Int32 hProcess;
public Int32 hThread;
public Int32 ProcessID;
public Int32 ThreadID;
}
// CreateProcess PInvoke API
[DllImport("CoreDll.DLL", SetLastError=true)]
private static extern int CreateProcess(
String imageName,
String cmdLine,
IntPtr lpProcessAttributes,
IntPtr lpThreadAttributes,
Int32 boolInheritHandles,
Int32 dwCreationFlags,
IntPtr lpEnvironment,
IntPtr lpszCurrentDir,
byte [] si,
ProcessInfo pi );
public bool CreateProcess( String ExeName, String CmdLine,
ProcessInfo pi )
{
if ( pi == null )
pi = new ProcessInfo();
byte [] si = new byte[128];
return CreateProcess(ExeName, CmdLine, IntPtr.Zero, IntPtr.Zero,
0, 0, IntPtr.Zero, IntPtr.Zero, si, pi) != 0;
}
public AfariaApp()
{
}
/// <summary>
/// Runs the application as a seperate process
/// </summary>
public void Connect(string channelSet)
{
// This is actually read in from a config file
string appPath = "\Program Files\app.exe"; // some path
this.CreateProcess(appPath, "ChannelSet=" + channelSet, null);
}
}