Created
April 26, 2021 11:18
-
-
Save mr5z/98c5c8496fe4063d752c5443dc1f3c72 to your computer and use it in GitHub Desktop.
Scheduled disposable objects to be registered in an IoC container where IDisposable is disallowed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void ScheduleDisposeResourceStreams() | |
{ | |
_ = Task.Factory.StartNew(async () => | |
{ | |
await Task.Delay(TimeSpan.FromMinutes(1)); | |
// `stream` creation happens right after the invocation of this | |
// They are in the same thread so no lock needed | |
jsonStream?.Dispose(); | |
jsonDocument?.Dispose(); | |
jsonStream = null; | |
jsonDocument = null; | |
}, default, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment