本文整理匯總了C#中Microsoft.Win32.TaskScheduler.TaskService.GetRunningTasks方法的典型用法代碼示例。如果您正苦於以下問題:C# TaskService.GetRunningTasks方法的具體用法?C# TaskService.GetRunningTasks怎麽用?C# TaskService.GetRunningTasks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Microsoft.Win32.TaskScheduler.TaskService
的用法示例。
在下文中一共展示了TaskService.GetRunningTasks方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: disableRunningZombieTasks
static void disableRunningZombieTasks()
{
using (TaskService ts = new TaskService())
{
if (!ts.Connected)
{
RunningTaskCollection runningTasks = ts.GetRunningTasks();
TaskFolder KNXFolder = ts.GetFolder("KNX");
for (var i = 0; i < runningTasks.Count; i++)
{
if (runningTasks[i].Folder.Path == "\\KNX")
{
if (runningTasks[i].NextRunTime < DateTime.Now)
{
runningTasks[i].Enabled = false;
runningTasks[i].Stop();
}
}
}
}
}
}
示例2: LongTest
internal static void LongTest(TaskService ts, System.IO.TextWriter output, params string[] arg)
{
string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
Version ver = ts.HighestSupportedVersion;
bool isV12 = (ver >= new Version(1, 2));
bool isV13 = (ver >= new Version(1, 3));
bool isV14 = (ver >= new Version(1, 4));
output.WriteLine("Highest version: " + ver);
output.WriteLine("Server: {0} ({1}); User: {2}\\{3}", ts.TargetServer, ts.Connected ? "Connected" : "Disconnected", ts.UserAccountDomain, ts.UserName);
output.WriteLine("Running tasks:");
foreach (RunningTask rt in ts.GetRunningTasks(true))
{
if (rt != null)
{
output.WriteLine("+ {0}, {1} ({2})", rt.Name, rt.Path, rt.State);
if (ver.Minor > 0)
output.WriteLine(" Current Action: " + rt.CurrentAction);
}
}
string filter = arg.Length > 0 ? arg[0] : string.Empty;
TaskFolder tf = ts.RootFolder;
TaskCollection tasks = tf.GetTasks(new Wildcard(filter));
output.WriteLine("\nRoot folder tasks matching \"{1}\" ({0}):", tasks.Count, filter);
foreach (Task t in tasks)
{
try
{
output.WriteLine("+ {0}, {1} ({2}) - {3}", t.Name, t.Definition.RegistrationInfo.Author, t.State, t.Definition.Settings.Compatibility);
foreach (Trigger trg in t.Definition.Triggers)
output.WriteLine(" + {0}", trg);
foreach (var act in t.Definition.Actions)
output.WriteLine(" = {0}", act);
}
catch { }
}
output.WriteLine("\n***Finding defrag task***");
Task ft = ts.FindTask("*defrag*");
if (ft != null)
output.WriteLine("Defrag task found at " + ft.Path);
else
output.WriteLine("Defrag task not found.");
TaskFolderCollection tfs = tf.SubFolders;
if (tfs.Count > 0)
{
output.WriteLine("\nSub folders:");
try
{
foreach (TaskFolder sf in tfs)
output.WriteLine("+ {0}", sf.Path);
}
catch (Exception ex)
{
output.WriteLine(ex.ToString());
}
}
if (isV12)
{
output.WriteLine("\n***Checking folder retrieval***");
try
{
const string testFolder = "David's TestFolder";
try { tf.CreateFolder(testFolder); }
catch (System.Runtime.InteropServices.COMException cex) { if (cex.ErrorCode != -2147024713) throw; }
catch { throw; }
TaskFolder sub = tf.SubFolders[testFolder];
output.WriteLine("\nSubfolder path: " + sub.Path);
try
{
ts.AddTask(testFolder + @"\MyTask", new DailyTrigger(), new ExecAction("notepad"));
output.WriteLine(" - Tasks: " + sub.Tasks.Count.ToString());
sub.DeleteTask("MyTask");
}
catch (Exception ex)
{
output.WriteLine(ex.ToString());
}
tf.DeleteFolder(testFolder);
}
catch (NotSupportedException) { }
catch (Exception ex)
{
output.WriteLine(ex.ToString());
}
}
output.WriteLine("\n***Checking task creation***");
try
{
TaskDefinition td = ts.NewTask();
td.Data = "Your data";
//td.Principal.UserId = "SYSTEM";
//td.Principal.LogonType = TaskLogonType.ServiceAccount;
if (isV12)
td.Principal.LogonType = TaskLogonType.S4U;
//.........這裏部分代碼省略.........
示例3: taskSchedule
static void taskSchedule()
{
Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
using (TaskService task = new TaskService())
{
Version version = task.HighestSupportedVersion;
bool newVer = (version >= new Version(1, 2));
Console.WriteLine(Resources.ResourceManager.GetString("HighestVersion" + version));
Console.WriteLine(Resources.ResourceManager.GetString("Target"));
Console.WriteLine(Resources.ResourceManager.GetString("RunTasks"));
foreach (RunningTask runningTasks in task.GetRunningTasks(true))
{
if (runningTasks != null)
{
Console.WriteLine(Resources.ResourceManager.GetString("RunPath" + runningTasks.Name + runningTasks.Path + runningTasks.State));
if (version.Minor > 0)
Console.WriteLine(Resources.ResourceManager.GetString("CurrentAction" + runningTasks.CurrentAction));
}
}
TaskFolder taskFolder = task.RootFolder;
Console.WriteLine(Resources.ResourceManager.GetString("TaskCount" + taskFolder.Tasks.Count));
foreach (Task tasks in taskFolder.Tasks)
{
try
{
Console.WriteLine(Resources.ResourceManager.GetString("TaskDefinition" + tasks.Name + tasks.Definition.RegistrationInfo.Author + tasks.State));
foreach (Trigger trigger in tasks.Definition.Triggers)
Console.WriteLine(Resources.ResourceManager.GetString("TaskTrigger" + trigger));
foreach (Microsoft.Win32.TaskScheduler.Action action in tasks.Definition.Actions)
Console.WriteLine(Resources.ResourceManager.GetString("TaskAction" + action));
}
catch (Exception)
{
throw;
}
}
Console.WriteLine(Resources.ResourceManager.GetString("CheckFolder"));
TaskFolderCollection taskFolderCollection = taskFolder.SubFolders;
if (taskFolderCollection.Count > 0)
{
Console.WriteLine(Resources.ResourceManager.GetString("SubFolders"));
try
{
foreach (TaskFolder standardFolder in taskFolderCollection)
Console.WriteLine(Resources.ResourceManager.GetString("FolderStandard" + standardFolder.Path));
}
catch (Exception err)
{
Console.WriteLine(err.ToString());
throw;
}
}
if (newVer)
{
Console.WriteLine(Resources.ResourceManager.GetString("RetrieveFolder"));
try
{
TaskFolder sub = taskFolder.SubFolders["Microsoft"];
Console.WriteLine(Resources.ResourceManager.GetString("SubFolderPath" + sub.Path));
}
catch (NotSupportedException) { }
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
throw;
}
}
Console.WriteLine(Resources.ResourceManager.GetString("CheckTask"));
try
{
TaskDefinition td = task.NewTask();
td.Principal.UserId = user;
td.Principal.LogonType = TaskLogonType.InteractiveToken;
td.RegistrationInfo.Author = "mikeyhalla";
td.RegistrationInfo.Description = "Launch GClient GT Edition with Administrative rights...";
td.Settings.Enabled = true;
td.Settings.Priority = ProcessPriorityClass.Normal;
td.Principal.RunLevel = TaskRunLevel.Highest;
td.RegistrationInfo.Source = "GClientGT";
td.RegistrationInfo.Version = new Version(0, 9);
td.Settings.AllowDemandStart = true;
td.Settings.Compatibility = TaskCompatibility.V2;
LogonTrigger lTrigger = (LogonTrigger)td.Triggers.Add(new LogonTrigger());
if (newVer)
{
lTrigger.UserId = user;
}
// Program to execute
td.Actions.Add(new ExecAction("\"" + Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Launcher.exe" + "\"", null, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)));
taskFolder.RegisterTaskDefinition("GClientGT", td, TaskCreation.CreateOrUpdate, null, null,
TaskLogonType.InteractiveToken, null);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
throw;
}
Task runningTask = taskFolder.Tasks["GClientGT"];
Console.WriteLine(Resources.ResourceManager.GetString("NextRun" + runningTask.NextRunTime));
//.........這裏部分代碼省略.........