Quantcast
Channel: Task Scheduler Managed Wrapper
Viewing all 2206 articles
Browse latest View live

New Post: implementing and ITaskHandlerStatus

$
0
0
i'm trying to schedule a com object implementing ITaskHandler interface
i've download your template project "COMTask"

Registering the task with this code everything works well
TaskService  ts = new TaskService();

TaskDefinition comTd = ts.NewTask();
comTd.RegistrationInfo.Description = "my first schedule on a COM object";

wt = new DailyTrigger();
wt.StartBoundary = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 14, 0, 0, 0, DateTimeKind.Local);
wt.Repetition.Interval = TimeSpan.FromMinutes(100);
comTd.Triggers.Add(wt);
             
ComHandlerAction cha = new ComHandlerAction(new Guid("{CE7D4428-8A77-4c5d-8A13-5CAB5D1EC734}"), "mydata");
comTd.Actions.Add(cha);
            
ts.RootFolder.RegisterTaskDefinition("My COM TAsk", comTd);
now i'd like to implement ITaskHandlerStatus interface in order to get the percentage of completion.

i've noticed that in your project,
into the file "TaskHandlerBase.cs" there is this interface "decorated" with a different "GUID" (different from the other one on the ITaskHandler interface)

so what does it mean? i have to register another COMtask with this guid?
is not sufficent implement this interface(ITaskHandlerStatus) into the com object i've already registered?

i've not understood well how to do

at first i thought to add the ITaskHandlerStatus interface to you COMTask class and implement its methods


your class
public class MyCOMTask : TaskHandlerBase
to
public class MyCOMTask : TaskHandlerBase, ITaskHandlerStatus
but if so, i don't understand the meaning of the second "GUID"

New Post: implementing and ITaskHandlerStatus

$
0
0
The ITaskHanderStatus interface is exposed through the StatusHandler property of TaskHandlerBase. Suppose you had a task that needed to write information to a log file every few seconds and terminate after 100 entries. You would create a Timer instance inside your TaskHandlerBase inherited class and then have a method like the following that would be called when that Timer's Elapsed event was called:
const int maxWrites = 100;
int writeCount = 0;

void timer_Elapsed(object sender, ElapsedEventArgs e)
{
  if (writeCount < maxWrites)
  {
    try
    {
      using (StreamWriter wri = File.AppendText(file))
        wri.WriteLine("Log entry {0}", DateTime.Now);

      this.StatusHandler.UpdateStatus((short)(++writeCount / maxWrites), string.Format("Log file started at {0}", lastWriteTime));
    }
    catch { }
  }

  if (writeCount >= maxWrites)
  {
    timer.Enabled = false;
    writeCount = 0;
    this.StatusHandler.TaskCompleted(0);
  }
}

New Post: TaskDefinition wil not run when not (live) connected to the sever

$
0
0
I'dp have the following issue.

In a (webapplication) I create a taskdefinition
        var cmd = @"restart.cmd";
        var taskName = string.Format("restart_{0}", DateTime.Now.ToString("yyyyMMMMdd_HHmm"));
TaskDefinition td = ts.NewTask();
            td.RegistrationInfo.Description = taskName;
            td.Triggers.Add(new TimeTrigger() {StartBoundary = DateTime.Now});
            td.Actions.Add(new ExecAction(cmd, null, null));
            td.Settings.Compatibility = TaskCompatibility.V2_1;
            td.Settings.ExecutionTimeLimit = TimeSpan.FromMinutes(15); // also tried without this line
            td.Principal.LogonType = TaskLogonType.InteractiveToken; // also tried without this line               
            task = ts.RootFolder.RegisterTaskDefinition(taskName, td, TaskCreation.CreateOrUpdate, @"domain\adminusername","pwd");
            // Remove the task we just created
            if (task != null)
            {
                task.Run();
                // Remove the task we just created
                ts.RootFolder.DeleteTask(taskName);
            }
The website is running on windows 2012. When I close the connection to the server, do not log off, the task is not runned any more. No error message, nothing. But it simply does not run.

Can there be a reason for this behaviour?

When I stay connected to the server it will keep continue to run.

Thanks in advance

Wijnand Beke
The Netherlands

New Post: Why not return a Null Object?

$
0
0
Imagine this code...
Function checkIfTaskFolderExists(folder As String) As Boolean
    Dim taskService As New TaskService

    If taskService.GetFolder(folder) IsNot Nothing Then
        Return True
    Else
        Return False
    End If
End Function

If checkIfTaskFolderExists("myTaskFolder") = True Then
    debug.writeline("the task folder exists")
Else
    debug.writeline("the task folder doesn't exist")
End If
But it doesn't work, an exception is thrown instead if you check for a task folder that doesn't exist. I don't understand why you would throw an exception instead of returning a Null Object that you could then check with an InNot Nothing check.

New Post: Why not return a Null Object?

$
0
0
This wrapper attempts to map to the Microsoft base library wherever possible. This is one of those instances. Changing at this point, after almost a decade of a released product, would constitute a breaking change. I agree that the pattern you suggest is preferable.

New Post: TaskDefinition wil not run when not (live) connected to the sever

$
0
0
I guess my first question is why even use tasks? You are effectively just launching a process immediately either using a trigger or forcing the Run of the task. Seems like you are adding complexity where none is needed. If your code doesn't fully represent what you're trying to accomplish, I would offer two suggestions: 1) The TimeTrigger will only run once and you are telling it to run Now, which by the time the task is registered is a time in the past. 2) You are immediately deleting the task so if it had not run already, it won't have a chance to run. You may also consider setting the td.Settings.DeleteExpiredTaskAfter to something like 5 seconds so the task will run once and then delete itself.

Created Unassigned: Separate out scheduler UI into user control [12115]

$
0
0
The UI for configuring the schedule of a task (once/daily/weekly/monthly) is very nice. I'd like it to be a user control, please. That way I could use it in a simpler interface, that is without the advanced settings.

Proposed patch follows.

Commented Unassigned: Separate out scheduler UI into user control [12115]

$
0
0
The UI for configuring the schedule of a task (once/daily/weekly/monthly) is very nice. I'd like it to be a user control, please. That way I could use it in a simpler interface, that is without the advanced settings.

![Image](https://www.codeplex.com/Download/AttachmentDownload.ashx?ProjectName=taskscheduler&WorkItemId=12115&FileAttachmentId=3988)

Proposed patch follows.
Comments: ** Comment from web user: iainiainiain **

Most of this patch is pretty boring. It's mainly a copy paste job of some code from TriggerEditDialog into a new public user control, ScheduledTriggerUI. Then the dialog is made to use the new control. I've made sure that the layout and translations survived this copy-pasting.

There's only one nontrivial thing. The DailyTriggerUI and WeeklyTriggerUI, etc, controls mutate the triggers they are given. These controls are used by the new ScheduledTriggerUI control. However, ScheduledTriggerUI control should instead take a copy of the trigger it's given, similar to TriggerEditDialog. The reason is that ScheduledTriggerUI has to instantiate new triggers when changing between daily and weekly, etc, so it can't always mutate the trigger it was given.

Becaused ScheduledTriggerUI doesn't mutate the trigger it was given, the TriggerEditDialog needs to merge two triggers. Namely, the schedule (when a scheduled trigger) needs to come from ScheduledTriggerUI.Trigger, and as before the advanced properties need to come from TriggerEditDialog.trigger. This explains the modifications to TriggerEditDialog.Trigger.get, plus the creation of two helper functions, TriggerEditDialog.TriggerMergeSchedule() and Trigger.CopyBaseClassProperties().

Hopefully that makes sense.


New Post: Creation of Task on Windows 7 remotely using Managed Wrapper.

$
0
0
While creating a remote task, I am getting error message "(18,8):LogonType:". What could be the issue? I am using logon type 'TaskLogonType.S4U' to create the task. Please help.

Source code checked in, #96085

$
0
0
* Separated out new CalendarTriggerUI control from TriggerEditDialog * Fixed bug in drop-down checked listbox items with multi-select * Fixed bug in CustomTrigger editor view * Added ICalendarTrigger interface to TimeTrigger

Commented Unassigned: Separate out scheduler UI into user control [12115]

$
0
0
The UI for configuring the schedule of a task (once/daily/weekly/monthly) is very nice. I'd like it to be a user control, please. That way I could use it in a simpler interface, that is without the advanced settings.

![Image](https://www.codeplex.com/Download/AttachmentDownload.ashx?ProjectName=taskscheduler&WorkItemId=12115&FileAttachmentId=3988)

Proposed patch follows.
Comments: ** Comment from web user: dahall **

The attached file (v4.0.zip) contains my work to do what you did. I approached it slightly differently as an effort to minimize changes. The control is called CalendarTriggerUI. If you get a TriggerTypeChanged event from the control, you will know that it has recreated the trigger. Thanks for your work on the patch as it saved me a great deal of time. On a positive note, I found bugs in two other controls while testing these changes. Try it out and let me know if it works for you.

New Post: Creation of Task on Windows 7 remotely using Managed Wrapper.

$
0
0
This is usually either that the account used when creating the TaskService object doesn't have rights to create the task with an S4U user, you haven't supplied a username in the RegisterTaskDefiniton method, or there is a combination of settings on the task's definition that can't be run interactively.

Commented Unassigned: Separate out scheduler UI into user control [12115]

$
0
0
The UI for configuring the schedule of a task (once/daily/weekly/monthly) is very nice. I'd like it to be a user control, please. That way I could use it in a simpler interface, that is without the advanced settings.

![Image](https://www.codeplex.com/Download/AttachmentDownload.ashx?ProjectName=taskscheduler&WorkItemId=12115&FileAttachmentId=3988)

Proposed patch follows.
Comments: ** Comment from web user: iainiainiain **

I totally support minimizing the changes, because you'll have to maintain this. (Also: thanks for this well maintained software. You must spend too much time on it ;) If you're ever in Edinburgh I'll buy you a drink.)

This works well, although there is one important bug and two trivial issues.

First, the new CalendarTriggerUI works well standalone. It's easy to use because when the trigger type changes, it copies over advanced properties such as .EndBoundary and .Repetition to the new trigger. There are just two small glitches with it:

1. Should it auto initialize with this.Trigger = new TimeTrigger()? At the moment, clicking around on an uninitialized CalendarTriggerUI causes a null reference exception. (If you click on the Daily radio button before anything else, it won't crash.)

2. Can we annotate ShowStartBoundary with [DefaultValue(false)]? Right now if you add a new CalendarTriggerUI to a form, the WinForms Properties window shows the property name in bold, because it thinks that the value of ShowStartBoundary has changed.

I've also tested the interaction of this refactoring with the TriggerEditDialog. It almost works well, except for the following bug:

3. Change from "On a schedule" to "At log on" back to "On a schedule". Then:

3a) As a minor point, the advanced Activate checkbox is visible. It wasn't visible the first time we were on a schedule, because the .StartBoundary is shown in the CalendarTriggerUI.

3b) Much more importantly, the return dialog.Trigger is incorrectly of type "At log on". Obviously it should be of type "On a schedule". And obviously if you then update the schedule properties such as start time or change it from daily to weekly, that should be reflected in the return dialog.Trigger.

Commented Unassigned: Separate out scheduler UI into user control [12115]

$
0
0
The UI for configuring the schedule of a task (once/daily/weekly/monthly) is very nice. I'd like it to be a user control, please. That way I could use it in a simpler interface, that is without the advanced settings.

![Image](https://www.codeplex.com/Download/AttachmentDownload.ashx?ProjectName=taskscheduler&WorkItemId=12115&FileAttachmentId=3988)

Proposed patch follows.
Comments: ** Comment from web user: dahall **

Thank you for your testing. I have replaced the v4.0.zip attachment with updated code that fixes the problems you identified. The ShowStartBoundary property wasn't even necessary, so I hid it (#1). I made the code more robust so that it could handle a null Trigger value rather than initializing with an arbitrary value (#2). 3a and 3b were related and work correctly and like they did originally. Let me know if you find any other problems.

Source code checked in, #96186

$
0
0
* Fixed bugs in new CalendarTriggerUI * Allowed for null value in Trigger.CopyProperties method

Commented Unassigned: Separate out scheduler UI into user control [12115]

$
0
0
The UI for configuring the schedule of a task (once/daily/weekly/monthly) is very nice. I'd like it to be a user control, please. That way I could use it in a simpler interface, that is without the advanced settings.

![Image](https://www.codeplex.com/Download/AttachmentDownload.ashx?ProjectName=taskscheduler&WorkItemId=12115&FileAttachmentId=3988)

Proposed patch follows.
Comments: ** Comment from web user: iainiainiain **

There's a minor problem with a null trigger. Namely, when the trigger is null, click on a once/daily/weekly/monthly radio. Then the startBoundary uses DateTime.Now instead of the date/time from the date/time pickers. (When you later change the date/time from the date/time pickers, it works).

The other changes LGTM. Thanks.

New Post: How to get all runtimes from a task ( planned and manuel triggered)

$
0
0
Hello,
i want to get a list of all runtimes from a task.
I have the following situation:

10:10 o'clock Task was planned
10:15 o'clock manuel triggered
10:20 o'clock manual triggered

With the method getRunTimes(), i get only the exectuion times for the planned one, not the manuel triggered.
Dim allRunsFromOneTask() As Date
allRunsFromOneTask = task.GetRunTimes(dStartdate.ToUniversalTime(), dEnddate.ToUniversalTime())
so i get the first one with getRunTimes-method and the last one with lastRunTime proberty but not the one in the middle.
allRunsFromOneTask(allRunsFromOneTask.Length - 1) = task.LastRunTime
Does someone have an idea ?

Commented Unassigned: Separate out scheduler UI into user control [12115]

$
0
0
The UI for configuring the schedule of a task (once/daily/weekly/monthly) is very nice. I'd like it to be a user control, please. That way I could use it in a simpler interface, that is without the advanced settings.

![Image](https://www.codeplex.com/Download/AttachmentDownload.ashx?ProjectName=taskscheduler&WorkItemId=12115&FileAttachmentId=3988)

Proposed patch follows.
Comments: ** Comment from web user: dahall **

I believe to have corrected the StartBoundary issue and have posted an updated zip file.

New Post: How to get all runtimes from a task ( planned and manuel triggered)

$
0
0
This is likely due to how Microsoft implemented the GetRunTimes method in the native COM library. I'm guessing they go to the Event Log and look for entries and chose to skip manually run entries. You too can use the TaskEventLog to go through all events looking for those that are important to you.

Source code checked in, #96191

$
0
0
* Fixed StartBoundary problem in CalendarTriggerUI
Viewing all 2206 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>