当前位置: 首页>>代码示例>>C#>>正文


C# TaskService.FindTask方法代码示例

本文整理汇总了C#中Microsoft.Win32.TaskScheduler.TaskService.FindTask方法的典型用法代码示例。如果您正苦于以下问题:C# TaskService.FindTask方法的具体用法?C# TaskService.FindTask怎么用?C# TaskService.FindTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Win32.TaskScheduler.TaskService的用法示例。


在下文中一共展示了TaskService.FindTask方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddStores2TaskScheduler

 public static void AddStores2TaskScheduler(string strStoresPath, string strActionPath)
 {
     string[] strXMLFiles = Directory.GetFiles(strStoresPath, "*.xml");
     TaskService ts = new TaskService();
     Console.ForegroundColor = ConsoleColor.Cyan;
     Console.WriteLine("");
     Console.WriteLine("Adding stores to the Task Scheduler");
     Console.ForegroundColor = ConsoleColor.Green;
     foreach (string strXMLFile in strXMLFiles)
     {
         string storeName = Path.GetFileName(strXMLFile);
         string taskName = @"BC Store " + storeName;
         Task t = ts.FindTask(taskName);
         if (t == null)
         {
             Console.WriteLine("  + " + storeName);
             DailyTrigger dt = new DailyTrigger();
             dt.StartBoundary = DateTime.Today.Date;
             dt.Repetition.Duration = TimeSpan.FromMinutes(1430);
             dt.Repetition.Interval = TimeSpan.FromMinutes(2);
             ts.AddTask(taskName, dt, new ExecAction(strActionPath, strXMLFile, null));
             Thread.Sleep(500);
         }
     }
     Console.ForegroundColor = ConsoleColor.Cyan;
     Console.WriteLine("All stores added");
     Console.WriteLine("");
     Console.WriteLine("");
     Console.ForegroundColor = ConsoleColor.White;
 }
开发者ID:rogerlio,项目名称:csharp-proj,代码行数:30,代码来源:Utils.cs

示例2: FindTask

 internal static void FindTask(TaskService ts, System.IO.TextWriter output, params string[] arg)
 {
     try
     {
         Task t = ts.FindTask(arg[0]);
         if (t == null)
             output.WriteLine(string.Format("Task '{0}' not found.", arg[0]));
         else
         {
             output.WriteLine(string.Format("Task '{0}' found. Created on {1:g} and last run on {2:g}.", t.Name, t.Definition.RegistrationInfo.Date, t.LastRunTime));
             if (t.Definition.Triggers.ContainsType(typeof(CustomTrigger)))
             {
                 foreach (var tr in t.Definition.Triggers)
                 {
                     CustomTrigger ct = tr as CustomTrigger;
                     if (ct != null && ct.Properties.Count > 0)
                     {
                         output.WriteLine("Custom Trigger Properties:");
                         int i = 0;
                         foreach (var name in ct.Properties.Names)
                             output.WriteLine("{0}. {1} = {2}", ++i, name, ct.Properties[name]);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         output.WriteLine(ex.ToString());
     }
 }
开发者ID:tablesmit,项目名称:task-scheduler-managed-wrapper,代码行数:31,代码来源:Program.cs

示例3: SaveTask

		void SaveTask()
		{
			bool isNewTask = true;
			try
			{
				var service = new TaskService();
				TaskDefinition td = service.NewTask();
				Microsoft.Win32.TaskScheduler.TriggerCollection trgCollection;
				var oldTriggerDate = new DateTime();

				Task task = service.FindTask(MainWindowViewModel.FreemiumDriverScanTaskName);

				if (task != null)
				{
					isNewTask = false;
					oldTriggerDate = task.Definition.Triggers.Count > 0 ? task.Definition.Triggers[0].StartBoundary.Date : DateTime.Today;
					task.Definition.Triggers.Clear();
					trgCollection = task.Definition.Triggers;
				}
				else
				{
					td.RegistrationInfo.Description = WPFLocalizeExtensionHelpers.GetUIString("WindowsTaskRegistrationInfo");
					td.Settings.Enabled = true;
					td.Actions.Add(new ExecAction(Environment.CurrentDirectory + @"\1Click.exe"));
					trgCollection = td.Triggers;
				}

				TimeSpan selectedTime = TimeSpan.Parse(((ComboBoxItem)AutoScanTime.SelectedValue).Content.ToString());
				switch (AutoScanPeriod.SelectedIndex)
				{
					case (int)Schedule.Daily:
						{
							var dTrigger = new DailyTrigger {DaysInterval = 1};
							if (isNewTask)
								dTrigger.StartBoundary = DateTime.Today.Date + selectedTime;
							else
								dTrigger.StartBoundary = oldTriggerDate + selectedTime;

							trgCollection.Add(dTrigger);
							break;
						}
					case (int)Schedule.Weekly:
						{
							var wTrigger = new WeeklyTrigger();
							switch (AutoScanDay.SelectedIndex)
							{
								case (int)DayOfWeek.Monday:
									{
										wTrigger.DaysOfWeek = DaysOfTheWeek.Monday;
										break;
									}
								case (int)DayOfWeek.Tuesday:
									{
										wTrigger.DaysOfWeek = DaysOfTheWeek.Tuesday;
										break;
									}
								case (int)DayOfWeek.Wednesday:
									{
										wTrigger.DaysOfWeek = DaysOfTheWeek.Wednesday;
										break;
									}
								case (int)DayOfWeek.Thursday:
									{
										wTrigger.DaysOfWeek = DaysOfTheWeek.Thursday;
										break;
									}
								case (int)DayOfWeek.Friday:
									{
										wTrigger.DaysOfWeek = DaysOfTheWeek.Friday;
										break;
									}
								case (int)DayOfWeek.Saturday:
									{
										wTrigger.DaysOfWeek = DaysOfTheWeek.Saturday;
										break;
									}
								case (int)DayOfWeek.Sunday:
									{
										wTrigger.DaysOfWeek = DaysOfTheWeek.Sunday;
										break;
									}
							}
							trgCollection.Add(wTrigger);
							foreach (WeeklyTrigger trg in trgCollection)
							{
								if (isNewTask)
									trg.StartBoundary = DateTime.Today.Date + selectedTime;
								else
									trg.StartBoundary = oldTriggerDate + selectedTime;
								trg.WeeksInterval = 1;
							}
							break;
						}
					case (int)Schedule.Monthly:
						{
							var mTrigger = new MonthlyTrigger();
							if (isNewTask)
								mTrigger.StartBoundary = DateTime.Today.Date + selectedTime;
							else
								mTrigger.StartBoundary = oldTriggerDate + selectedTime;
//.........这里部分代码省略.........
开发者ID:nullkuhl,项目名称:fdu-dev,代码行数:101,代码来源:PanelScan.xaml.cs

示例4: CreateOrActivate

		public bool CreateOrActivate(String TaskName, String FullExecuteableFileName, TimeSpan RetryIntervall)
			{
			//if (!IsAdministrator())
			//	return false;
			using (TaskService taskService = new TaskService())
				{
				Task task = taskService.FindTask(TaskName);
				if (task == null)
					{
					TaskDefinition taskDefinition = CreateTask(taskService, TaskName, RetryIntervall);
					taskDefinition.Actions.Add(new ExecAction(FullExecuteableFileName));
					
					taskDefinition.RegistrationInfo.Description = $"WPMedia created Task for " +
									$"{Path.GetFileNameWithoutExtension(FullExecuteableFileName)}";
					taskDefinition.Settings.MultipleInstances = TaskInstancesPolicy.IgnoreNew;
					taskDefinition.Settings.AllowDemandStart = true;
					taskDefinition.Settings.AllowHardTerminate = false;
					taskDefinition.Settings.DisallowStartIfOnBatteries = false;
					taskDefinition.RegistrationInfo.Author = "WPMediaAutoRegistration";
					if (taskDefinition.Validate())
						task = taskService.RootFolder.RegisterTaskDefinition(TaskName, taskDefinition);
					else
						throw new Exception($"{TaskName} Scheduling for {FullExecuteableFileName} failed");
					}
				task.Enabled = true;
				}
			return true;
			}
开发者ID:heinzsack,项目名称:DEV,代码行数:28,代码来源:TaskSchedulingFunctions.cs

示例5: StartupTaskExists

 public static bool StartupTaskExists()
 {
     using (TaskService _taskService = new TaskService())
     {
         return _taskService.FindTask(_taskName) != null;
     }
 }
开发者ID:CSpellmanKrieg,项目名称:SidebarDiagnostics,代码行数:7,代码来源:Helpers.cs

示例6: clearSchedules

 public void clearSchedules()
 {
     string strTaskID = "";
     try
     {
         // Get the service on the local machine
         TaskService ts = new TaskService();
         // Delete Schedules
         DataTable dt = this.GetSchedules(1);
         foreach (DataRow dr in dt.Rows)
         {
             strTaskID = dr["TaskID"].ToString();
             if (ts.FindTask(strTaskID, true) != null)
             {
                 // Remove the task we just created
                 ts.RootFolder.DeleteTask(strTaskID);
             }
             // Delete schedules follow taskid
             this.DeleleSchedules(strTaskID);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
开发者ID:colobaena,项目名称:prediction-tool,代码行数:26,代码来源:clsOddBO.cs

示例7: PersistTask

        public static bool PersistTask(bool startAtLogon, bool startForAllUsers)
        {
            WinTasks.TaskService ts = new WinTasks.TaskService();
            try
            {
                WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();
                bool isElevated = (new WindowsPrincipal(currentIdentity).IsInRole(WindowsBuiltInRole.Administrator));
                WinTasks.Task task = ts.FindTask(Application.ProductName, false);

                if (startAtLogon)
                {
                    if (startForAllUsers && !isElevated)
                    {
                        return PersistTaskElevated(startAtLogon, startForAllUsers);
                    }
                    else
                    {
                        WinTasks.LogonTrigger trigger = (WinTasks.LogonTrigger)WinTasks.LogonTrigger.CreateTrigger(WinTasks.TaskTriggerType.Logon);
                        trigger.Enabled = true;
                        trigger.StartBoundary = DateTime.Today;
                        if (startForAllUsers)
                            trigger.UserId = null;
                        else
                            trigger.UserId = currentIdentity.Name;

                        WinTasks.ExecAction action = (WinTasks.ExecAction)WinTasks.ExecAction.CreateAction(WinTasks.TaskActionType.Execute);
                        action.Path = Application.ExecutablePath;
                        action.WorkingDirectory = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

                        if (task == null)
                        {
                            task = ts.AddTask(Application.ProductName, trigger, action, currentIdentity.Name);
                        }
                        else
                        {
                            task.Definition.Triggers.Clear();
                            task.Definition.Triggers.Add(trigger);
                            task.Definition.Actions.Clear();
                            task.Definition.Actions.Add(action);
                            task.RegisterChanges();
                        }
                    }
                }
                else if (task != null)
                {
                    ts.GetFolder("\\").DeleteTask(task.Name);
                }
            }
            catch
            {
                return false;
            }
            finally
            {
                ts.Dispose();
            }
            return true;
        }
开发者ID:Mrunited12,项目名称:realtemp-4-rtss,代码行数:58,代码来源:TaskPersistance.cs

示例8: btnInput_Click

        private void btnInput_Click(object sender, EventArgs e)
        {
            string strTaskID = "";
            string appPath = System.Configuration.ConfigurationManager.AppSettings["AutoGetOdds"];
            Application.DoEvents();
            Cursor.Current = Cursors.WaitCursor;

            try
            {
                // Get the service on the local machine
                TaskService ts = new TaskService();
                // Delete Schedules
                DataTable dt = oddBO.GetSchedules(1);
                foreach (DataRow dr in dt.Rows)
                {
                    strTaskID = dr["TaskID"].ToString();
                    if (ts.FindTask(strTaskID, true) != null)
                    {
                        // Remove the task we just created
                        ts.RootFolder.DeleteTask(strTaskID);
                    }
                    // Delete schedules follow taskid
                    oddBO.DeleleSchedules(strTaskID);
                }
                DateTime currDate = dtpDate.Value;
                // Create Schedules
                dt = oddBO.GetSchedules(0, currDate);
                foreach (DataRow dr in dt.Rows)
                {
                    strTaskID = dr["TaskID"].ToString();
                    // Create a new task definition and assign properties
                    TaskDefinition td = ts.NewTask();

                    Trigger t = new TimeTrigger();
                    t.StartBoundary = Convert.ToDateTime(dr["RunTime"].ToString());

                    td.RegistrationInfo.Description = "Get odd at " + dr["RunTime"].ToString();

                    // Create a trigger that will fire the task at this time every other day
                    td.Triggers.Add(t);

                    // Create an action that will launch Notepad whenever the trigger fires
                    td.Actions.Add(new ExecAction(appPath, "\"" + strTaskID + "\"", null));

                    // Register the task in the root folder
                    ts.RootFolder.RegisterTaskDefinition(strTaskID, td);
                }
                MessageBox.Show("Schedules have inputed successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.WaitCursor;
            }
        }
开发者ID:colobaena,项目名称:prediction-tool,代码行数:58,代码来源:InputSchedules.cs

示例9: GetTaskByName

        /// <summary>
        /// Gets task by its name
        /// </summary>
        /// <param name="taskName">task name</param>
        /// <returns></returns>
        public static Task GetTaskByName(string taskName)
        {
            Task task = null;
            try
            {
                TaskService service = new TaskService();
                task = service.FindTask(taskName, true);

            }
            catch { }

            return task;
        }
开发者ID:nullkuhl,项目名称:driverGalaxy-dev,代码行数:18,代码来源:TaskManager.cs

示例10: DeleteTask

        public static void DeleteTask(string taskName)
        {
            Task task = null;
            try
            {
                TaskService service = new TaskService();
                task = service.FindTask(taskName, true);

                if (task != null)
                    service.RootFolder.DeleteTask(taskName);
            }
            catch { }
        }
开发者ID:nullkuhl,项目名称:driverGalaxy-dev,代码行数:13,代码来源:TaskManager.cs

示例11: UnScheduleBackup

        public void UnScheduleBackup()
        {
            // Get the service on the local machine
            using (var ts = new TaskService())
            {
                Task existingTask = ts.FindTask("EC2 Backup");

                if (null != existingTask)
                {
                    // Remove the task we just created
                    ts.RootFolder.DeleteTask(existingTask.Name);
                }
            }
        }
开发者ID:escherrer,项目名称:EC2Utilities,代码行数:14,代码来源:ScheduleEngine.cs

示例12: UpdateTaskStatus

        public static void UpdateTaskStatus(string taskName, bool isEnabled)
        {
            try
            {
                TaskService service = new TaskService();
                Task task = service.FindTask(taskName, true);

                if (task != null)
                {
                    task.Enabled = isEnabled;
                    task.RegisterChanges();
                }
            }
            catch{}
        }
开发者ID:nullkuhl,项目名称:fdu-dev,代码行数:15,代码来源:TaskManager.cs

示例13: Disable

		public bool Disable(String TaskName)
			{
			if (!IsAdministrator())
				return false;

			using (TaskService taskService = new TaskService())
				{
				Task task = taskService.FindTask(TaskName);
				if (task == null)
					{
					return false;
					}
				task.Enabled = false;
				return true;
				}
			}
开发者ID:heinzsack,项目名称:DEV,代码行数:16,代码来源:TaskSchedulingFunctions.cs

示例14: SkylineNightly

        public SkylineNightly()
        {
            InitializeComponent();
            startTime.Value = DateTime.Parse(Settings.Default.StartTime);
            textBoxFolder.Text = Settings.Default.NightlyFolder;
            includePerfTests.Checked = Settings.Default.PerfTests;
            if (string.IsNullOrEmpty(textBoxFolder.Text))
                textBoxFolder.Text = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                    "SkylineNightly"); // Not L10N

            using (var ts = new TaskService())
            {
                var task = ts.FindTask(Nightly.NIGHTLY_TASK_NAME);
                enabled.Checked = (task != null);
            }
        }
开发者ID:lgatto,项目名称:proteowizard,代码行数:17,代码来源:SkylineNightly.cs

示例15: Start

        public static void Start(string command)
        {
            using (var ts = new TaskService())
            {
                var td = ts.NewTask();
                td.RegistrationInfo.Description = "start " + taskName + " limited user";
                td.Actions.Add(new ExecAction(command));
                td.Settings.Priority = ProcessPriorityClass.Normal;
                td.Principal.RunLevel = TaskRunLevel.LUA;
                td.Settings.AllowDemandStart = true;
                td.Settings.DisallowStartIfOnBatteries = false;
                td.Settings.StopIfGoingOnBatteries = false;

                var ret = ts.RootFolder.RegisterTaskDefinition(taskName, td);

                var fooTask = ts.FindTask(taskName, true);
                fooTask.Run();

                ts.RootFolder.DeleteTask(taskName);
            }
        }
开发者ID:vipoo,项目名称:iRacingApplicationVersionManager,代码行数:21,代码来源:DeElevatedProcess.cs


注:本文中的Microsoft.Win32.TaskScheduler.TaskService.FindTask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。