Example #1
0
        public async Task DisposeWorkplace(bool immediately = false)
        {
            if (!IsInitialized)
            {
                throw new InvalidOperationException();
            }

            // closing IDEs in reverse order
            while (IDEs.Count > 0)
            {
                await CloseIDE(IDEs.Last(), immediately);
            }

            bool locked;

            foreach (IInputDevice inputDevice in InputDevices)
            {
                if (inputDevice != null && inputDevice.IsInitialized)
                {
                    locked = false;
                    if (inputDevice.IsLockingRequiredForDispose())
                    {
                        IOmonitor.IdleForLock(inputDevice, out locked);
                    }
                    inputDevice.Dispose();
                    if (locked)
                    {
                        IOmonitor.Unlock(inputDevice);
                    }
                }
            }
            foreach (IOutputDevice outputDevice in OutputDevices)
            {
                if (outputDevice != null && outputDevice.IsInitialized)
                {
                    locked = false;
                    if (outputDevice.IsLockingRequiredForDispose())
                    {
                        IOmonitor.IdleForLock(outputDevice, out locked);
                    }
                    outputDevice.Dispose();
                    if (locked)
                    {
                        IOmonitor.Unlock(outputDevice);
                    }
                }
            }
            foreach (IExtraWorkplaceComponent extraComponent in ExtraComponents
                     .Where(e => e is IDisposable))
            {
                (extraComponent as IDisposable)?.Dispose();
            }

            IsInitialized = false;
            OnGotUpdated();
        }
Example #2
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);
            });
        }