Task Schedule Service exception on BeginDeleteTask

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

When working with Task Schedule Service you might get following exception when invoking BeginDeletTask:

ArgumentException: Value Cannot be null.

image

This exception is thrown by executing of following code:

protected void Button2_Click(object sender, EventArgs e)
        {
           
DistributedTask task = getTask();

 

            TaskSchedulerClient client = ServiceReferences.CreateImport1("Tasks");
    

           
IAsyncResult asyncResult = client.BeginDeleteTask(task, cb => { }, null);


            client.EndDeleteTask(asyncResult);
      

        }

    

        private DistributedTask getTask()
        {
           
TaskSchedulerClient client = ServiceReferences.CreateImport1("Tasks"
);
           
IAsyncResult asyncResultAllTasks = client.BeginGetAllTasks(cb =>
            {       
      

                Debug.WriteLine("");
           

            }, null);

            ReadOnlyCollection<DistributedTask> tasks = client.EndGetAllTasks(asyncResultAllTasks);
          

             return tasks.Count > 0 ? tasks[0] : null;
        }

To workaround this issue, insert the yellow line in the code which stops distributed the task.:

protected void Button2_Click(object sender, EventArgs e)
{
   DistributedTask task = getTask();

   TaskSchedulerClient client = ServiceReferences.CreateImport1("Tasks");

   task.SelfLink = new Uri(client.EndpointAddress.AbsoluteUri);

   IAsyncResult asyncResult = client.BeginDeleteTask(task, cb => { }, null);

   client.EndDeleteTask(asyncResult);

}


Posted Sep 03 2011, 04:27 PM by Damir Dobric
Filed under: , , ,
developers.de is a .Net Community Blog powered by daenet GmbH.