How can I close a NSUrlSessionTask?

EnricoRossiniEnricoRossini USMember ✭✭✭✭

Hi guys,
I'm trying to resolve my previous post about sending images. The code from @DannyC is very useful. Now I have an issue with Task.

To avoid to fill all space on a device, I should send 25 images at each time and for each image I create a CreateUploadTask. For that I check if all tasks are completed with this code:

    /// <summary>
    /// Gets the pending task.
    /// </summary>
    /// <returns>The pending task.</returns>
    /// <remarks>For demo purposes we are only starting a single task so that's why we are returning only one.</remarks>
    private async Task<NSUrlSessionTask> GetPendingTask()
    {
        NSUrlSessionTask uploadTask = null;

        if (session != null)
        {
            var tasks = await session.GetTasks2Async();

            var taskList = tasks.UploadTasks;
            if (taskList.Count() > 0)
                uploadTask = taskList[0];
        }

        return uploadTask;
    }

Unless an image is sent and the event DidCompleteWithError raises, the Task still running. How can I close a task then?

Answers

Sign In or Register to comment.