1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Runtime.InteropServices;
- using static MiniTerm.Native.ProcessApi;
- namespace MiniTerm
- {
- /// <summary>
- /// Represents an instance of a process.
- /// </summary>
- internal sealed class Process : IDisposable
- {
- public Process(STARTUPINFOEX startupInfo, PROCESS_INFORMATION processInfo)
- {
- StartupInfo = startupInfo;
- ProcessInfo = processInfo;
- }
- public STARTUPINFOEX StartupInfo { get; }
- public PROCESS_INFORMATION ProcessInfo { get; }
- #region IDisposable Support
- private bool disposedValue = false; // To detect redundant calls
- void Dispose(bool disposing)
- {
- if (!disposedValue)
- {
- if (disposing)
- {
- // dispose managed state (managed objects).
- }
- // dispose unmanaged state
- // Free the attribute list
- if (StartupInfo.lpAttributeList != IntPtr.Zero)
- {
- DeleteProcThreadAttributeList(StartupInfo.lpAttributeList);
- Marshal.FreeHGlobal(StartupInfo.lpAttributeList);
- }
- // Close process and thread handles
- if (ProcessInfo.hProcess != IntPtr.Zero)
- {
- CloseHandle(ProcessInfo.hProcess);
- }
- if (ProcessInfo.hThread != IntPtr.Zero)
- {
- CloseHandle(ProcessInfo.hThread);
- }
- disposedValue = true;
- }
- }
- ~Process()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- Dispose(false);
- }
- // This code added to correctly implement the disposable pattern.
- public void Dispose()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- Dispose(true);
- // use the following line if the finalizer is overridden above.
- GC.SuppressFinalize(this);
- }
- #endregion
- }
- }
|