Skip to content

Commit

Permalink
Add Watch() method to TaskHelper (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
tibel committed Apr 13, 2015
1 parent 10c8631 commit 1c853b9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
4 changes: 2 additions & 2 deletions build/Weakly.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<metadata>
<id>Weakly</id>
<title>Weakly</title>
<version>2.4.2</version>
<version>2.5.0</version>
<authors>Thomas Ibel</authors>
<description>Weakly is a collection of some useful weak-reference types available as portable class library for net45+win8+wp8+wpa81.</description>
<language>en-US</language>
<licenseUrl>https://raw.github.com/tibel/Weakly/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/tibel/Weakly</projectUrl>
<iconUrl>https://raw.github.com/tibel/Weakly/master/build/weakly_icon.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes>Bugfix release</releaseNotes>
<releaseNotes>add TaskWatched event</releaseNotes>
<copyright>Copyright Thomas Ibel 2013-2015</copyright>
<tags>
Weakly WeakReference WeakAction WeakFunc WeakDelegate WeakCollection WeakValueDictionary WeakEventHandler WeakEventSource Async Task
Expand Down
4 changes: 2 additions & 2 deletions src/GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

[assembly: CLSCompliant(true)]

[assembly: AssemblyVersion("2.4.0.0")]
[assembly: AssemblyFileVersion("2.4.2.0")]
[assembly: AssemblyVersion("2.5.0.0")]
[assembly: AssemblyFileVersion("2.5.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
namespace Weakly
{
/// <summary>
/// Provides data for the event that is raised when a faulted <see cref="Task"/> is observed.
/// Provides data for <see cref="TaskHelper"/> events.
/// </summary>
public sealed class FaultedTaskEventArgs : EventArgs
public sealed class TaskEventArgs : EventArgs
{
private readonly Task _task;

/// <summary>
/// Initializes a new instance of the <see cref="FaultedTaskEventArgs"/> class with the faulted task.
/// <summary>
/// Initializes a new instance of the <see cref="TaskEventArgs"/> class.
/// </summary>
/// <param name="task">The Task that has faulted.</param>
public FaultedTaskEventArgs(Task task)
/// <param name="task">The supplied Task.</param>
public TaskEventArgs(Task task)
{
if (task == null)
throw new ArgumentNullException("task");
Expand All @@ -23,7 +23,7 @@ public FaultedTaskEventArgs(Task task)
}

/// <summary>
/// The faulted task.
/// The supplied task.
/// </summary>
public Task Task
{
Expand Down
23 changes: 21 additions & 2 deletions src/Weakly/Tasks/TaskHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ public static Task<T> FailFastOnException<T>(this Task<T> task)
/// <summary>
/// Occurs when a faulted <see cref="Task"/> is observed.
/// </summary>
public static event EventHandler<FaultedTaskEventArgs> TaskFaulted;
public static event EventHandler<TaskEventArgs> TaskFaulted;

private static void OnTaskFaulted(Task task)
{
var handler = TaskFaulted;
if (handler != null)
handler(null, new FaultedTaskEventArgs(task));
handler(null, new TaskEventArgs(task));
}

/// <summary>
Expand Down Expand Up @@ -197,6 +197,25 @@ public static void PropagateExceptionsTo(this Task task, SynchronizationContext

#endregion

/// <summary>
/// Occurs when a <see cref="Task"/> is watched.
/// </summary>
public static event EventHandler<TaskEventArgs> TaskWatched;

/// <summary>
/// Triggers the <see cref="TaskWatched"/> event for the supplied <paramref name="task"/>.
/// </summary>
/// <param name="task">The task to watch.</param>
public static void Watch(this Task task)
{
if (task == null)
throw new ArgumentNullException("task");

var handler = TaskWatched;
if (handler != null)
handler(null, new TaskEventArgs(task));
}

/// <summary>
/// Waits for the task to complete execution, returning the task's final status.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Weakly/Weakly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Reflection\ReflectionPath.cs" />
<Compile Include="Reflection\ManagedRuntimeType.cs" />
<Compile Include="Tasks\FaultedTaskEventArgs.cs" />
<Compile Include="Tasks\TaskEventArgs.cs" />
<Compile Include="Tasks\TaskHelper.cs" />
</ItemGroup>
<ItemGroup />
Expand Down

0 comments on commit 1c853b9

Please sign in to comment.