本文整理汇总了C#中STARTUPINFO.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# STARTUPINFO.Dispose方法的具体用法?C# STARTUPINFO.Dispose怎么用?C# STARTUPINFO.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类STARTUPINFO
的用法示例。
在下文中一共展示了STARTUPINFO.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateProcess
public static bool CreateProcess(ProcessStartInfo startInfo, bool createSuspended, out SafeProcessHandle process, out SafeThreadHandle thread, out uint processID, out uint threadID)
{
StringBuilder cmdLine = BuildCommandLine(startInfo.FileName, startInfo.Arguments);
STARTUPINFO lpStartupInfo = new STARTUPINFO();
PROCESS_INFORMATION lpProcessInformation = new PROCESS_INFORMATION();
SafeProcessHandle processHandle = new SafeProcessHandle();
SafeThreadHandle threadHandle = new SafeThreadHandle();
GCHandle environment = new GCHandle();
int creationFlags = 0;
bool success;
creationFlags = CREATE_DEFAULT_ERROR_MODE | CREATE_PRESERVE_CODE_AUTHZ_LEVEL;
if (createSuspended)
creationFlags |= CREATE_SUSPENDED;
if (startInfo.CreateNoWindow)
creationFlags |= CREATE_NO_WINDOW;
IntPtr pinnedEnvironment = IntPtr.Zero;
if (startInfo.EnvironmentVariables != null)
{
bool unicode = false;
if (IsNt)
{
creationFlags |= CREATE_UNICODE_ENVIRONMENT;
unicode = true;
}
environment = GCHandle.Alloc(EnvironmentToByteArray(startInfo.EnvironmentVariables, unicode), GCHandleType.Pinned);
pinnedEnvironment = environment.AddrOfPinnedObject();
}
string workingDirectory = startInfo.WorkingDirectory;
if (workingDirectory == "")
workingDirectory = Environment.CurrentDirectory;
success = CreateProcess(null, cmdLine, null, null, false, creationFlags, pinnedEnvironment, workingDirectory, lpStartupInfo, lpProcessInformation);
if ((lpProcessInformation.hProcess != IntPtr.Zero) && (lpProcessInformation.hProcess != INVALID_HANDLE_VALUE))
processHandle.InitialSetHandle(lpProcessInformation.hProcess);
if ((lpProcessInformation.hThread != IntPtr.Zero) && (lpProcessInformation.hThread != INVALID_HANDLE_VALUE))
threadHandle.InitialSetHandle(lpProcessInformation.hThread);
if (environment.IsAllocated)
environment.Free();
lpStartupInfo.Dispose();
if (success && !processHandle.IsInvalid && !threadHandle.IsInvalid)
{
process = processHandle;
thread = threadHandle;
processID = lpProcessInformation.dwProcessId;
threadID = lpProcessInformation.dwThreadId;
return true;
}
process = null;
thread = null;
processID = 0;
threadID = 0;
return false;
}