Class Poco::TaskManager
Author: Applied Informatics Software Engineering GmbH and Contributors

# Poco

# class TaskManager

Library: Foundation
Package: Tasks
Header: Poco/TaskManager.h

## Description

The TaskManager manages a collection of tasks and monitors their lifetime.

A TaskManager has a built-in NotificationCenter that is used to send out notifications on task progress and task states. See the TaskNotification class and its subclasses for the various events that result in a notification. To keep the number of notifications small, a TaskProgressNotification will only be sent out once in 100 milliseconds.

## Member Summary

Member Functions: addObserver, cancelAll, count, joinAll, postNotification, removeObserver, start, taskCancelled, taskFailed, taskFinished, taskList, taskProgress, taskStarted

## Types

### TaskList

typedef std::list < TaskPtr > TaskList;

### TaskPtr

typedef AutoPtr < Task > TaskPtr;

## Constructors

### TaskManager

TaskManager();

Creates the TaskManager, using the default ThreadPool.

### TaskManager

TaskManager(
ThreadPool & pool
);

Creates the TaskManager, using the given ThreadPool.

## Destructor

### ~TaskManager

~TaskManager();

Destroys the TaskManager.

## Member Functions

### addObserver

void addObserver(
const AbstractObserver & observer
);

Registers an observer with the NotificationCenter. Usage:

    Observer<MyClass, MyNotification> obs(*this, &MyClass::handleNotification);
    notificationCenter.addObserver(obs);

### cancelAll

void cancelAll();

Requests cancellation of all tasks.

### count

int count() const;

Returns the number of tasks in the internal task list.

### joinAll

void joinAll();

Waits for the completion of all the threads in the TaskManager's thread pool.

Note: joinAll() will wait for ALL tasks in the TaskManager's ThreadPool to complete. If the ThreadPool has threads created by other facilities, these threads must also complete before joinAll() can return.

### removeObserver

void removeObserver(
const AbstractObserver & observer
);

Unregisters an observer with the NotificationCenter.

### start

void start(
Task * pTask
);

Starts the given task in a thread obtained from the thread pool.

The TaskManager takes ownership of the Task object and deletes it when it it finished.

### taskList

TaskList taskList() const;

Returns a copy of the internal task list.

### postNotification

void postNotification(
const Notification::Ptr & pNf
);

Posts a notification to the task manager's notification center.

### taskCancelled

void taskCancelled(
Task * pTask
);

### taskFailed

void taskFailed(
Task * pTask,
const Exception & exc
);

### taskFinished

void taskFinished(
Task * pTask
);

### taskProgress

void taskProgress(
Task * pTask,
float progress
);

### taskStarted

void taskStarted(
Task * pTask
);

## Variables

### MIN_PROGRESS_NOTIFICATION_INTERVAL

static const int MIN_PROGRESS_NOTIFICATION_INTERVAL;