@@ -33,29 +33,28 @@ public static bool IsActive(this Task target)
3333 /// <summary>
3434 /// Checks the status of the task and attempts to start it if waiting to start (TaskStatus.Created).
3535 /// </summary>
36+ /// <param name="target">The task to ensure start.</param>
3637 /// <param name="scheduler">Optional scheduler to use.</param>
3738 /// <returns>True if start attempt was successful.</returns>
3839 public static bool EnsureStarted ( this Task target , TaskScheduler scheduler = null )
3940 {
4041 if ( target == null ) throw new NullReferenceException ( ) ;
4142
42- if ( target . Status == TaskStatus . Created )
43+ if ( target . Status != TaskStatus . Created ) return false ;
44+ try
4345 {
44- try
45- {
46- if ( scheduler == null )
47- target . Start ( ) ;
48- else
49- target . Start ( scheduler ) ;
46+ if ( scheduler == null )
47+ target . Start ( ) ;
48+ else
49+ target . Start ( scheduler ) ;
5050
51- return true ;
52- }
53- catch ( InvalidOperationException )
54- {
55- // Even though we've checked the status, it's possible it could have been started. We can't guarantee proper handling without a trap here.
56- if ( target . Status == TaskStatus . Created )
57- throw ; // Something wierd must have happened if we arrived here.
58- }
51+ return true ;
52+ }
53+ catch ( InvalidOperationException )
54+ {
55+ // Even though we've checked the status, it's possible it could have been started. We can't guarantee proper handling without a trap here.
56+ if ( target . Status == TaskStatus . Created )
57+ throw ; // Something wierd must have happened if we arrived here.
5958 }
6059
6160 return false ;
@@ -65,6 +64,7 @@ public static bool EnsureStarted(this Task target, TaskScheduler scheduler = nul
6564 /// Utility method that can be chained with other methods for reacting to Task results. Only invokes the action if completed and not cancelled.
6665 /// </summary>
6766 /// <typeparam name="TTask">The return type is the same as the target.</typeparam>
67+ /// <param name="target">The task.</param>
6868 /// <param name="action">The action to perform if fullfulled.</param>
6969 /// <returns>The target object. Allows for method chaining.</returns>
7070 public static TTask OnFullfilled < TTask > ( this TTask target , Action action )
@@ -81,7 +81,8 @@ public static TTask OnFullfilled<TTask>(this TTask target, Action action)
8181 /// <summary>
8282 /// Utility method that can be chained with other methods for reacting to Task results. Only invokes the action if completed and not cancelled.
8383 /// </summary>
84- /// <typeparam name="TTask">The return type is the same as the target.</typeparam>
84+ /// <typeparam name="T">The return type is the same as the target.</typeparam>
85+ /// <param name="target">The task.</param>
8586 /// <param name="action">The action to perform if fullfulled.</param>
8687 /// <returns>The target object. Allows for method chaining.</returns>
8788 public static Task < T > OnFullfilled < T > ( this Task < T > target , Action < T > action )
@@ -97,7 +98,9 @@ public static Task<T> OnFullfilled<T>(this Task<T> target, Action<T> action)
9798 /// <summary>
9899 /// Utility method that can be chained with other methods for reacting to Task results. Only invokes the action if completed and not cancelled.
99100 /// </summary>
100- /// <typeparam name="TTask">The return type is the same as the target.</typeparam>
101+ /// <typeparam name="TTask">The task type.</typeparam>
102+ /// <typeparam name="T">The return type of the task.</typeparam>
103+ /// <param name="target">The task.</param>
101104 /// <param name="action">The action to perform if fullfulled.</param>
102105 /// <returns>The target object. Allows for method chaining.</returns>
103106 public static TTask OnFullfilled < TTask , T > ( this TTask target , Func < T > action )
@@ -115,6 +118,7 @@ public static TTask OnFullfilled<TTask, T>(this TTask target, Func<T> action)
115118 /// Utility method that can be chained with other methods for reacting to Task results. Only invokes the action if faulted.
116119 /// </summary>
117120 /// <typeparam name="TTask">The return type is the same as the target.</typeparam>
121+ /// <param name="target">The task.</param>
118122 /// <param name="action">The action to perform if faulted.</param>
119123 /// <returns>The target object. Allows for method chaining.</returns>
120124 public static TTask OnFaulted < TTask > ( this TTask target , Action < Exception > action )
@@ -133,6 +137,7 @@ public static TTask OnFaulted<TTask>(this TTask target, Action<Exception> action
133137 /// Utility method that can be chained with other methods for reacting to Task results. Only invokes the action if cancelled.
134138 /// </summary>
135139 /// <typeparam name="TTask">The return type is the same as the target.</typeparam>
140+ /// <param name="target">The task.</param>
136141 /// <param name="action">The action to perform if cancelled.</param>
137142 /// <returns>The target object. Allows for method chaining.</returns>
138143 public static TTask OnCancelled < TTask > ( this TTask target , Action action )
@@ -149,7 +154,9 @@ public static TTask OnCancelled<TTask>(this TTask target, Action action)
149154 /// <summary>
150155 /// Utility method that can be chained with other methods for reacting to Task results. Only invokes the action if cancelled.
151156 /// </summary>
152- /// <typeparam name="TTask">The return type is the same as the target.</typeparam>
157+ /// <typeparam name="TTask">The task type.</typeparam>
158+ /// <typeparam name="T">The return type of the task.</typeparam>
159+ /// <param name="target">The task.</param>
153160 /// <param name="action">The action to perform if cancelled.</param>
154161 /// <returns>The target object. Allows for method chaining.</returns>
155162 public static TTask OnCancelled < TTask , T > ( this TTask target , Func < T > action )
0 commit comments