コード例 #1
0
 public static void ReleaseLoader(CSerialPortLibraryLoader loader)
 {
     lock (loaderInstances)
     {
         loader.refCount--;
         if (loader.refCount == 0)
         {
             ((IDisposable)loader).Dispose();
             loaderInstances.Remove(loader.dynamicLinkLibrariesPath.FullName);
         }
     }
 }
コード例 #2
0
        public static CSerialPortLibraryLoader GetOrCreateLoader(DirectoryInfo dynamicLinkLibrariesPath)
        {
            if (!dynamicLinkLibrariesPath.Exists)
            {
                throw new DirectoryNotFoundException();
            }

            lock (loaderInstances)
            {
                if (loaderInstances.ContainsKey(dynamicLinkLibrariesPath.FullName))
                {
                    var instance = loaderInstances[dynamicLinkLibrariesPath.FullName];
                    instance.refCount++;
                    return(instance);
                }

                var returnedInstance = new CSerialPortLibraryLoader(dynamicLinkLibrariesPath);
                loaderInstances[dynamicLinkLibrariesPath.FullName] = returnedInstance;
                return(returnedInstance);
            }
        }
コード例 #3
0
 public void Dispose()
 {
     instance.Dispose();
     CSerialPortLibraryLoader.ReleaseLoader(this.libraryLoader);
 }
コード例 #4
0
 public CSerialPortManager(DirectoryInfo dynamicLinkLibrariesPath)
 {
     this.libraryLoader = CSerialPortLibraryLoader.GetOrCreateLoader(dynamicLinkLibrariesPath);
     instance           = new CSerialPortInstance(this, libraryLoader.GetInteropDelegate <CreateNewInstance>().Invoke());
 }