In the software that I write, I read some data from an external device (connected via USB). The drivers that were provided to me (the dll file) are not thread safe, and only one instance can be used at a time. I have to write a shell for these drivers in C #. Given that I have a multi-threaded application, I would like to make sure that:
- Only one instance is always used (maybe the wrapper is a single?)
- Is it possible to remove drivers and resources there (IDisposable?)
From Disposable Singleton, I see that opinions are divided whether Singleton can be IDisposable or not. Maybe there is a better solution for both? Any help is appreciated.
At the moment, I have an IDisposable singleton, as shown below:
using System; using System.Runtime.InteropServices; namespace Philips.Research.Myotrace.DataReading.Devices { class MyDevice: IDisposable { private static volatile MyDeviceInstance; private static object SyncRoot = new Object(); private bool disposed = false; private MyDevice() {
multithreading c # design-patterns idisposable
Daniel Gruszczyk
source share