Exemplo n.º 1
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }
            if (disposing)
            {
                if (hasOnDisposingCalled == false)
                {
                    hasOnDisposingCalled = true;
                    OnDisposing(EventArgs.Empty);
                    if (disposed)
                    {
                        return;
                    }
                }

                // dispose managed objects, and dispose objects that implement IDisposable
                if (EachDeviceStatusMonitoringTimer != null)
                {
                    EachDeviceStatusMonitoringTimer.Dispose(); EachDeviceStatusMonitoringTimer = null;
                }
                if (OnDeviceConnectedDelayTimer != null)
                {
                    OnDeviceConnectedDelayTimer.Stop(); OnDeviceConnectedDelayTimer.Dispose(); OnDeviceConnectedDelayTimer = null;
                }
                if (OnDeviceDisconnectedDelayTimer != null)
                {
                    OnDeviceDisconnectedDelayTimer.Stop(); OnDeviceDisconnectedDelayTimer.Dispose(); OnDeviceDisconnectedDelayTimer = null;
                }
                if (MessageReceivingForm != null)
                {
                    MessageReceivingForm.CurrentDevice = null;
                }
                if (DeviceList != null)
                {
                    foreach (var device in DeviceList)
                    {
                        device.Close();
                    }
                    DeviceList.Clear();
                    DeviceList = null;
                }
                if (MessageReceivingForm != null)
                {
                    MessageReceivingForm.Dispose(); MessageReceivingForm = null;
                }
            }
            // release any unmanaged objects and set the object references to null
            disposed = true;
            OnDisposed(EventArgs.Empty);
        }
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }
            if (disposing)
            {
                if (hasOnDisposingCalled == false)
                {
                    hasOnDisposingCalled = true;
                    OnDisposing(EventArgs.Empty);
                    if (disposed)
                    {
                        return;
                    }
                }

                // dispose managed objects, and dispose objects that implement IDisposable
#if false
                if (EachDeviceStatusMonitoringTimer != null)
                {
                    EachDeviceStatusMonitoringTimer.Dispose(); EachDeviceStatusMonitoringTimer = null;
                }
#endif
                if (DeviceList != null)
                {
                    foreach (var device in DeviceList)
                    {
                        device.Close();
                    }
                    DeviceList.Clear();
                    DeviceList = null;
                }
            }
            // release any unmanaged objects and set the object references to null
            disposed = true;
            OnDisposed(EventArgs.Empty);
        }