Exemplo n.º 1
0
        public void InitializeIOdeviceInIndividualThread(IOutputDevice outputDevice)
        {
            Task.Factory.StartNew(() =>
            {
                Thread.CurrentThread.Name            = $"{outputDevice} Output Thread";
                IReinitializeable reinitOutputDevice = outputDevice as IReinitializeable;

                bool locked = false;
                try
                {
                    if (!outputDevice.IsInitialized)
                    {
                        if (outputDevice.IsLockingRequiredForInitialize())
                        {
                            IOmonitor.IdleForLock(outputDevice, out locked);
                        }
                        outputDevice.Initialize(this);
                    }
                    else if (reinitOutputDevice != null)
                    {
                        if (outputDevice.IsLockingRequiredForInitialize() ||
                            outputDevice.IsLockingRequiredForDispose())
                        {
                            IOmonitor.IdleForLock(outputDevice, out locked);
                        }
                        reinitOutputDevice.Reinitialize(this, true);
                    }
                    else
                    {
                        return;
                    }
                }
                finally
                {
                    if (locked)
                    {
                        IOmonitor.Unlock(outputDevice);
                    }
                }

                IOmonitor.IdleWhile(() => outputDevice.IsInitialized);
            });
        }