Bobby Black
Bobby Black

Reputation: 3

Queue Task ReExecution

Upvotes: 0

Views: 98

Answers (1)

Ben McIntosh
Ben McIntosh

Reputation: 1552

Here is an example of how to get a return value from a Task:

http://msdn.microsoft.com/en-us/library/dd537613

The MSDN article for Task (http://msdn.microsoft.com/en-us/library/dd270682.aspx) says that:

A task may only be started and run only once. Any attempts to schedule a task a second time will result in an exception.

I would recommend finding a way to rewrite your code using Task.Factory.StartNew() instead of new Task().Start. Here is a good article on the difference:

http://blogs.msdn.com/b/pfxteam/archive/2010/06/13/10024153.aspx

Why not queue up enum values instead of the Tasks themselves, and then write a small function to run a task based on the enum value. It could look something like:

public static void StartTask(Actions action)
{
    if (action == Actions.Print)
    {
        Task t = new Task(() => print("hello world"));
        t.Start();
    }
}

Incorporate the return values based on the first example and then you're all set.

Upvotes: 0

Related Questions