Should job processing be eliminated quickly?

I provide a TPL based method:

    private Task AddItemAsync(Uri url, CancellationToken token)
    {
        if (url == null)
            throw new ArgumentNullException("url");

        var result = Task.Factory.StartNew(() => 
        {
            // Do some stuff here
        }, token);
        return result;
    }

Now I wonder if it is possible to immediately throw an exception or throw it inside the task .StartNew {} stuff.

+4
source share
3 answers

Throwing it immediately is almost certainly the right approach. I am sure that someone might think of some unclear reason, but not based on your question, it seems that urlit is 100% required. In other words, if he was not always , then this may be a good reason not to drop him there.

But even then I will try to find a way to find out that I will need it.

Throw this exception on the background thread, there will be a hard line for the hoe.

+3

, null ( ), . . , .

- try/finally finally.

+2

-. , , (, ) . , .

URL-, .

+2

All Articles