示例#1
0
    {
        self::setProperty("count", 100);
    }
    protected function doInBackground($parameters)
    {
        sleep(2);
        self::setProperty("count", self::getProperty("count") + $parameters[0]);
        sleep(1);
        return $parameters[1] . self::getProperty("count");
    }
    protected function onPostExecute($result)
    {
        echo "{$result}\n";
    }
}
$task = new TestTask();
$task->execute(array(100, 'task 1: '));
sleep(5);
$task2 = new TestTask();
$task2->execute(array(100, 'task 2: '));
echo "task 1: " . $task->getStatus() . "\n";
echo "task 2: " . $task2->getStatus() . "\n";
sleep(10);
if ($task->getStatus() == 'RUNNING') {
    $task->cancel();
}
if ($task2->getStatus() == 'RUNNING') {
    $task2->cancel();
}
echo "task 1: " . $task->getStatus() . "\n";
echo "task 2: " . $task2->getStatus() . "\n";