@@ -12,7 +12,7 @@ public static class TaskSchedulerUtils
12
12
13
13
public static void RunOnBatteryTask ( )
14
14
{
15
- if ( ! TaskExists ( TASK_NAME_ON_BATTERY ) )
15
+ if ( ! TaskAndFolderExists ( TASK_NAME_ON_BATTERY ) )
16
16
{
17
17
string description = "The GPUPrefSwitcher service runs this task once when the system is considered on battery." +
18
18
"\n It is up to you to add actions (e.g. start a script)." ;
@@ -25,7 +25,7 @@ public static void RunOnBatteryTask()
25
25
26
26
public static void RunPluggedInTask ( )
27
27
{
28
- if ( ! TaskExists ( TASK_NAME_PLUGGED_IN ) )
28
+ if ( ! TaskAndFolderExists ( TASK_NAME_PLUGGED_IN ) )
29
29
{
30
30
string description = "The GPUPrefSwitcher service runs this task once when the system is considered plugged in." +
31
31
"\n It is up to you to add actions (e.g. start a script)." ;
@@ -36,11 +36,28 @@ public static void RunPluggedInTask()
36
36
RunTask ( TASK_NAME_PLUGGED_IN ) ;
37
37
}
38
38
39
- public static bool TaskExists ( string taskName )
39
+ public static bool TaskAndFolderExists ( string taskName )
40
40
{
41
41
using ( TaskService taskService = new ( ) )
42
42
{
43
- return taskService . FindTask ( taskName , false ) != null ;
43
+
44
+ TaskFolder gpuPrefSwitcherFolder = taskService . GetFolder ( FOLDER_NAME ) ;
45
+ if ( gpuPrefSwitcherFolder == null ) return false ;
46
+
47
+ // Get the folder with the specified name
48
+ TaskFolder folder = taskService . RootFolder . SubFolders [ FOLDER_NAME ] ;
49
+
50
+ // Iterate through the tasks in the folder
51
+ foreach ( Task task in folder . Tasks )
52
+ {
53
+ // Check if the task has the specified name
54
+ if ( task . Name . Equals ( taskName , StringComparison . OrdinalIgnoreCase ) )
55
+ {
56
+ return true ; // Return the task if found
57
+ }
58
+ }
59
+ return false ;
60
+ //return taskService.FindTask(taskName, true) != null;
44
61
}
45
62
}
46
63
0 commit comments