forked from Oliviaophia/SmartTaskbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. 用互斥量防止SmartTaskbar和TaskbarSwitcher进程重复启动 2. 使SmartTaskbar和TaskbarSwitcher在同一个作业中,防止系统托盘意外关闭时,自动隐藏任务栏功能依然保持工作 3. 首次启动应用时会弹出程序正在运行消息 4. 安装和卸载程序时能正常的关闭仍在运行的程序和删除相应的设置文件 5. 一些性能的提升
- Loading branch information
1 parent
2d13452
commit aafbb77
Showing
13 changed files
with
214 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
using static SmartTaskbar.SafeNativeMethods; | ||
|
||
namespace SmartTaskbar | ||
{ | ||
//https://stackoverflow.com/questions/3342941/kill-child-process-when-parent-process-is-killed | ||
static class ChildProcessTracker | ||
{ | ||
/// <summary> | ||
/// Add the process to be tracked. If our current process is killed, the child processes | ||
/// that we are tracking will be automatically killed, too. If the child process terminates | ||
/// first, that's fine, too.</summary> | ||
/// <param name="process"></param> | ||
public static void AddProcess(Process process) | ||
{ | ||
if (s_jobHandle != IntPtr.Zero) | ||
{ | ||
bool success = AssignProcessToJobObject(s_jobHandle, process.Handle); | ||
if (!success) | ||
return; | ||
} | ||
} | ||
|
||
static ChildProcessTracker() | ||
{ | ||
// This feature requires Windows 8 or later. To support Windows 7 requires | ||
// registry settings to be added if you are using Visual Studio plus an | ||
// app.manifest change. | ||
// https://stackoverflow.com/a/4232259/386091 | ||
// https://stackoverflow.com/a/9507862/386091 | ||
//if (Environment.OSVersion.Version < new Version(6, 2)) | ||
// return; | ||
|
||
// The job name is optional (and can be null) but it helps with diagnostics. | ||
// If it's not null, it has to be unique. Use SysInternals' Handle command-line | ||
// utility: handle -a ChildProcessTracker | ||
string jobName = "ChildProcessTracker" + Process.GetCurrentProcess().Id; | ||
s_jobHandle = CreateJobObjectW(IntPtr.Zero, jobName); | ||
|
||
var info = new JOBOBJECT_BASIC_LIMIT_INFORMATION | ||
{ | ||
|
||
// This is the key flag. When our process is killed, Windows will automatically | ||
// close the job handle, and when that happens, we want the child processes to | ||
// be killed, too. | ||
LimitFlags = JOBOBJECTLIMIT.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE | ||
}; | ||
|
||
var extendedInfo = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION | ||
{ | ||
BasicLimitInformation = info | ||
}; | ||
|
||
int length = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION)); | ||
IntPtr extendedInfoPtr = Marshal.AllocHGlobal(length); | ||
try | ||
{ | ||
Marshal.StructureToPtr(extendedInfo, extendedInfoPtr, false); | ||
SetInformationJobObject(s_jobHandle, JobObjectInfoType.ExtendedLimitInformation, extendedInfoPtr, (uint)length); | ||
} | ||
finally | ||
{ | ||
Marshal.FreeHGlobal(extendedInfoPtr); | ||
} | ||
} | ||
|
||
// Windows will automatically close any open job handles when our process terminates. | ||
// This can be verified by using SysInternals' Handle utility. When the job handle | ||
// is closed, the child processes will be killed. | ||
private static readonly IntPtr s_jobHandle; | ||
} | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.