diff --git a/Implab/Promise.cs b/Implab/Promise.cs --- a/Implab/Promise.cs +++ b/Implab/Promise.cs @@ -127,7 +127,12 @@ namespace Implab { public bool Cancel() { lock(this) { if (m_state == State.Unresolved && m_cancellable) { - m_state = State.Cancelled; + m_state = State.Cancelled; + EventHandler temp = Cancelled; + + if (temp != null) + temp(this,new EventArgs()); + return true; } else return false; diff --git a/Implab/Safe.cs b/Implab/Safe.cs new file mode 100644 --- /dev/null +++ b/Implab/Safe.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Implab +{ + public static class Safe + { + public static void Dispose(ref T obj) where T : IDisposable + { + if (obj != null) + { + obj.Dispose(); + obj = default(T); + } + } + } +}