Skip to content

Commit 6c76130

Browse files
authored
Avoid throwing exceptions after resource disposal (#501)
Changed the PropertyChanged method in the PropertyChangedObservable class to return instead of throwing an InvalidOperationException when _isDisposed is true. Added a return check in the SourcePropertyChangedEventHandler method of the PropertyPathNode class when _isDisposed is true. Changed the PropertyChanged method in the SimplePropertyObservable class to return instead of throwing an InvalidOperationException when _isDisposed is true.
1 parent eb92dc2 commit 6c76130

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

Source/ReactiveProperty.Core/Internals/PropertyChangedObservable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Subscription(INotifyPropertyChanged notifyPropertyChanged, IObserver<Prop
3131

3232
private void PropertyChanged(object? _, PropertyChangedEventArgs e)
3333
{
34-
if (_isDisposed) throw new InvalidOperationException();
34+
if (_isDisposed) return;
3535
_observer.OnNext(e);
3636
}
3737

Source/ReactiveProperty.Core/Internals/PropertyPathNode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public bool SetPropertyPathValue(object? value)
113113

114114
private void SourcePropertyChangedEventHandler(object? sender, PropertyChangedEventArgs e)
115115
{
116+
if (_isDisposed) return;
116117
if (e.PropertyName == PropertyName || string.IsNullOrEmpty(e.PropertyName))
117118
{
118119
Next?.UpdateSource(GetPropertyValue());

Source/ReactiveProperty.Core/Internals/SimplePropertyObservable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public Subscription(TSubject subject, Func<TSubject, TProperty> accessor, string
6060

6161
private void PropertyChanged(object? sender, PropertyChangedEventArgs e)
6262
{
63+
if (_isDisposed) return;
6364
if (e.PropertyName != _propertyName && !string.IsNullOrEmpty(e.PropertyName)) return;
64-
if (_isDisposed) throw new InvalidOperationException();
6565

6666
try
6767
{

0 commit comments

Comments
 (0)