private void linkTaskSchedule_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { ITask task = TaskSchedulerFactory.CreateTask(); ITaskScheduler tasksched = TaskSchedulerFactory.CreateTaskScheduler(); String taskName = "mdumpfs - Backup Task"; Int32 i = 0; // param System.Text.StringBuilder sbParam = new System.Text.StringBuilder(); if (textExclude.Text.Trim().Length > 0) { sbParam.Append(" /re \"" + textExclude.Text.Trim() + "\""); } sbParam.Append(" /nogui /l " + numericLimitDay.Value); // タスクスケジュールアイテム 設定 task.SetApplicationName(Application.ExecutablePath); task.SetComment("バックアップ元: " + comboBackupDir.Text + "\r\n" + "保存先: " + comboDestDir.Text); task.SetParameters( String.Format("\"{0}\" \"{1}\" {2}", comboBackupDir.Text.TrimEnd(new Char[] { Path.DirectorySeparatorChar }), comboDestDir.Text.TrimEnd(new Char[] { Path.DirectorySeparatorChar }), sbParam.ToString())); // タスクスケジュールアイテム 保存 while (true) { try { tasksched.AddWorkItem(taskName, task); break; } catch (System.Runtime.InteropServices.COMException ex) { if (ex.ErrorCode == -2147024816) { // ファイルがある。 taskName = "mdumpfs - Backup Task (" + (i++) + ")"; } else { // 不明なエラー return; } } } // タスクスケジュールアイテム ダイアログ表示 if (task != null) { task.EditWorkItem(this.Handle, 0); } //tasksched.NewWorkItem("Test Task", Guids.CTask, Guids.ITask, out taskItem); }