Why Task.CurrentId returns Nullable<int> instead of int?


sorry if it's obvious question. i'm curious, why task.currentid returns nullable<int> (reference type) instead of int (value type)?

task.currentid returns task id (positive integer) if current thread belongs task, , returns null otherwise.

using nullable<int> creates overhead (garbage collection);. why not returns -1 when current thread not belong task?

thanks in advance.

edit: nullable<int> struct not class, not have problem garbage collection.

because -1 valid id, other negative numbers.

null the error return value.


let's talk mvvm: http://social.msdn.microsoft.com/forums/en-us/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 please mark post helpfull , answers respectively.



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

  1. https://blog.stephencleary.com/2013/03/taskcurrentid-in-async-methods.html

    ReplyDelete

Post a Comment

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

How to Share webservice object to all user