Creating an Ambiguous Trigger

[This is preliminary documentation and subject to change.]

To create an ambiguous trigger, first create a TASK_TRIGGER structure and set the ambiguous time or date members to –1. Then set this structure to a trigger object by calling the ITaskTrigger::SetTrigger method.

The following example creates an ambiguous trigger where the starting time, 7 p.m., is known but the day, month, and year are not. This trigger can be used, for example, to represent multiple episodes of a show that is broadcast every weeknight at 7 p.m.:

ITaskTrigger *pTaskTrig;
TASK_TRIGGER tt;
HRESULT hr;
 
memset(&tt, 0, sizeof(tt));
tt.cbTriggerSize = sizeof(TASK_TRIGGER);
tt.TriggerType = TASK_TIME_TRIGGER_ONCE;
tt.rgFlags = 0;
tt.wStartMinute = 0;
//Set the ambiguous time members
tt.wBeginYear = -1;
tt.wBeginMonth = -1;
tt.wBeginDay = -1;
//set the starting time to 7pm
tt.wStartHour = 19;
 
//Create an instance of a task trigger
if (FAILED(hr = CoCreateInstance(CLSID_TaskTrigger, NULL, CLSCTX_INPROC_SERVER, IID_ITaskTrigger, (LPVOID *) &pTaskTrig)))
  return hr;
 
//Set the ambiguous trigger in the task
if (FAILED(hr = pTaskTrigger->SetTrigger(&tt)))
{
  pTaskTrigger->Release();
  return hr;
}
else
{
  //... Additional code that uses the trigger
 
  pTaskTrigger->Release();
  return NOERROR;
}
 

You can set any number of the TASK_SCHEDULER structure members to –1. For example, you can make a trigger that is ambiguous only in the day, or the month, or the year. So, if you know that a show was on during January 1998 but don't know what day, you can set the month to 1, the year to 1998, and the day to –1.

To determine whether a trigger is ambiguous, you can call the ITaskTrigger::GetTrigger method and check whether any of the date or time members in the TASK_TRIGGER structure are set to –1.

To locate more information about TASK_TRIGGER and the ITaskTrigger interface, see Further Information on Television Services for the Client.