Change the type of Task.m_action to Delegate
authorPetr Onderka <gsvick@gmail.com>
Mon, 28 Nov 2016 18:18:00 +0000 (19:18 +0100)
committerPetr Onderka <gsvick@gmail.com>
Mon, 28 Nov 2016 18:21:17 +0000 (19:21 +0100)
This makes the code more strongly typed and avoids some casts.

src/mscorlib/src/System/Threading/Tasks/Task.cs
src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs
src/mscorlib/src/System/Threading/Tasks/future.cs

index 36f8401a4d8de4200d328e6dba3f8857b80fc6f5..c48d3c456fd50be2db69076d1df21716e22dc44a 100644 (file)
@@ -152,7 +152,7 @@ namespace System.Threading.Tasks
 
         private volatile int m_taskId; // this task's unique ID. initialized only if it is ever requested
 
-        internal object m_action;    // The body of the task.  Might be Action<object>, Action<TState> or Action.  Or possibly a Func.
+        internal Delegate m_action;    // The body of the task.  Might be Action<object>, Action<TState> or Action.  Or possibly a Func.
         // If m_action is set to null it will indicate that we operate in the
         // "externally triggered completion" mode, which is exclusively meant 
         // for the signalling Task<TResult> (aka. promise). In this mode,
@@ -580,7 +580,7 @@ namespace System.Threading.Tasks
         /// <param name="cancellationToken">A CancellationToken for the Task.</param>
         /// <param name="creationOptions">Options to customize behavior of Task.</param>
         /// <param name="internalOptions">Internal options to customize behavior of Task.</param>
-        internal void TaskConstructorCore(object action, object state, CancellationToken cancellationToken,
+        internal void TaskConstructorCore(Delegate action, object state, CancellationToken cancellationToken,
             TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler)
         {
             m_action = action;
@@ -753,7 +753,7 @@ namespace System.Threading.Tasks
         {
             get
             {
-                Delegate d = (Delegate)m_action;
+                Delegate d = m_action;
                 return d != null ? d.Method.ToString() : "{null}";
             }
         }
@@ -1912,7 +1912,7 @@ namespace System.Threading.Tasks
             if (AsyncCausalityTracer.LoggingOn && (Options & (TaskCreationOptions)InternalTaskOptions.ContinuationTask) == 0)
             {
                 //For all other task than TaskContinuations we want to log. TaskContinuations log in their constructor
-                AsyncCausalityTracer.TraceOperationCreation(CausalityTraceLevel.Required, this.Id, "Task: "+((Delegate)m_action).Method.Name, 0);
+                AsyncCausalityTracer.TraceOperationCreation(CausalityTraceLevel.Required, this.Id, "Task: " + m_action.Method.Name, 0);
             }
 
 
index 4c035dfddb456dddcfaceaad991cf03fa8e84690..b078d276276a47182eb4cfcdb8edbe968eeb9e1c 100644 (file)
@@ -305,7 +305,7 @@ namespace System.Threading.Tasks
             m_options = options;
             m_taskScheduler = scheduler;
             if (AsyncCausalityTracer.LoggingOn)
-                AsyncCausalityTracer.TraceOperationCreation(CausalityTraceLevel.Required, m_task.Id, "Task.ContinueWith: " + ((Delegate)task.m_action).Method.Name, 0);
+                AsyncCausalityTracer.TraceOperationCreation(CausalityTraceLevel.Required, m_task.Id, "Task.ContinueWith: " + task.m_action.Method.Name, 0);
 
             if (Task.s_asyncDebuggingEnabled)
             {
@@ -374,7 +374,7 @@ namespace System.Threading.Tasks
                 return m_task.GetDelegateContinuationsForDebugger();
             }
 
-            return new Delegate[] { m_task.m_action as Delegate };
+            return new Delegate[] { m_task.m_action };
         }
     }
 
index 39e6ca1d45f975d1c1ef8a252e5d8618bbd09e4d..d5b2bdb1243cd3c467eb86ad33b908fce76a29cb 100644 (file)
@@ -447,7 +447,7 @@ namespace System.Threading.Tasks
         {
             get
             {
-                Delegate d = (Delegate)m_action;
+                Delegate d = m_action;
                 return d != null ? d.Method.ToString() : "{null}";
             }
         }