public void Dispose() { if (mDisposed) { return; } if (mBackgroundCancellationTokenSource != null && !mBackgroundCancellationTokenSource.IsCancellationRequested) { try { mBackgroundCancellationTokenSource.Cancel(); } catch { } } // must dispose first as the background task uses the other objects to be disposed if (mBackgroundTask != null) { // wait for the task to exit before disposing it try { mBackgroundTask.Wait(); } catch { } try { mBackgroundTask.Dispose(); } catch { } } if (mIdleBlock != null) { try { mIdleBlock.Dispose(); } catch { } } if (mBackgroundReleaser != null) { try { mBackgroundReleaser.Dispose(); } catch { } } if (mBackgroundAwaiter != null) { try { mBackgroundAwaiter.Dispose(); } catch { } } if (mBackgroundCancellationTokenSource != null) { try { mBackgroundCancellationTokenSource.Dispose(); } catch { } } if (mConnection != null) { try { mConnection.Dispose(); } catch { } } mDisposed = true; }