c# - How to dispose a resource shared between UI thread and background thread -


lets start ui thread (wpf, winforms fine too), , ui thread creates background thread somework (threadpool) , when completed background thread updates ui (using dispatcher). ui thread shares resouce background thread , needs disposed of when background thread completes process.

what best way achieve this, dispose resouce background thread when finishes job? if cannot use resouce ui thread after creating thread don't know when background thread completes , vice versa. (and no async/await features avaiable here). dealing ui thread here, need keep gui active time.

my preference 1 thread "own" resource , manage it. if ui thread owns can "loan" resource background thread ui thread still responsible disposing of it. way ui thread can use resource , knows whether it's disposed or not.

if possible it's better background worker "own" resource can dispose sounds not possible in situation.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -