Click or drag to resize
Task Scheduler Managed Class Library

TaskCollection Class

Contains all the tasks that are registered within a TaskFolder. This class has no public constructor and can only be accessed via the properties and functions within TaskFolder.
Inheritance Hierarchy
SystemObject
  Microsoft.Win32.TaskSchedulerTaskCollection

Namespace: Microsoft.Win32.TaskScheduler
Assembly: Microsoft.Win32.TaskScheduler (in Microsoft.Win32.TaskScheduler.dll) Version: 2.12.0
Syntax
C#
public sealed class TaskCollection : IEnumerable, 
	IDisposable
Request Example View Source

The TaskCollection type exposes the following members.

Properties
 NameDescription
Public propertyCountGets the number of registered tasks in the collection.
Public propertyItemInt32Gets the specified registered task from the collection.
Public propertyItemStringGets the named registered task from the collection.
Top
Methods
 NameDescription
Public methodDisposeReleases all resources used by this class.
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Public methodExistsDetermines whether the specified task exists.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
Public methodGetEnumeratorGets the collection enumerator for the register task collection.
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Public methodToStringReturns a String that represents this instance.
(Overrides ObjectToString)
Top
Remarks
Potentially breaking change in 1.6.2 and later where under V1 the list previously included the '.job' extension on the task name. This has been removed so that it is consistent with V2.
Example
C#
public class Program
             {
                bool RootFolderHasTask(string taskName)
                {
                   if (TaskService.Instance.RootFolder.Tasks.Count > 0)
                   {
                      return TaskService.Instance.RootFolder.Tasks.Exists(taskName);
                   }
                   return false;
                }

                TaskCollection GetRootTasksStartingWith(string value)
                {
                   var pattern = $"^{Regex.Escape(value)}.*$";
                   return TaskService.Instance.RootFolder.GetTasks(new Regex(pattern));
                }

                public static void Main()
                {
                   foreach (var task in GetRootTasksStartingWith("MyCo"))
                      if (RootFolderHasTask(task.Name))
                         Console.WriteLine(task.Name);
                }
             }
See Also