Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #949 from bijington/issue-910-object-disposed-exce…
Browse files Browse the repository at this point in the history
…ption

Added locking around the disposal of the observer
  • Loading branch information
jamesmontemagno authored Sep 22, 2022
2 parents d87341a + f532b9f commit cacba4e
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/Media.Plugin/iOS/MediaPickerDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public void DisplayPopover(bool hideFirst = false)

UIDeviceOrientation? orientation;
NSObject observer;
readonly object observerDisposeLock = new object();
readonly UIViewController viewController;
readonly UIImagePickerControllerSourceType source;
TaskCompletionSource<List<MediaFile>> tcs = new TaskCompletionSource<List<MediaFile>>();
Expand Down Expand Up @@ -203,18 +204,24 @@ void RemoveOrientationChangeObserverAndNotifications()

if (observer != null)
{
try
{
NSNotificationCenter.DefaultCenter.RemoveObserver(observer);
}
catch (Exception ex)
lock (observerDisposeLock)
{
Debug.WriteLine(ex);
}
if (observer != null)
{
try
{
NSNotificationCenter.DefaultCenter.RemoveObserver(observer);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}

observer.Dispose();
observer = null;
}
}
}
observer?.Dispose();
observer = null;
}

void DidRotate(NSNotification notice)
Expand Down

0 comments on commit cacba4e

Please sign in to comment.