Handle task cancellation in the .NET client

#2178
Made changes as per code review feedback

#2234
Made changes as per code review feedback

#2178