2014-01-14 220 views

回答

6

如果您申請使用類似:

_token = thing.WeakSubscribe(() => parameter.Value, HandleValueChanged); 

那麼你可以取消使用:

_token.Dispose(); 
_token = null; 

這就要求在https://github.com/MvvmCross/MvvmCross/blob/v3.1/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxWeakEventSubscription.cs#L91Dispose代碼:

protected virtual void Dispose(bool disposing) 
    { 
     if (disposing) 
     { 
      RemoveEventHandler(); 
     } 
    } 

    private void RemoveEventHandler() 
    { 
     if (!_subscribed) 
      return; 

     var source = (TSource) _sourceReference.Target; 
     if (source != null) 
     { 
      _sourceEventInfo.GetRemoveMethod().Invoke(source, new object[] {CreateEventHandler()}); 
      _subscribed = false; 
     } 
    } 
+0

如果這個「沒有按」 t工作「,然後請考慮添加複製問題的代碼 - 最好是一個塊有人可以閱讀和運行的代碼(請參閱http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-question.aspx)。 – Stuart

+0

它工作正常。非常感謝。 – user3089631