Esempio n. 1
0
        /// <summary>
        /// Cleans up all associated things and the client himself.<br/>
        ///   Drops all channels and disconnects all channel.
        /// </summary>
        public void Dispose()
        {
            if (this.notDisposing)
            {
                this.notDisposing = false;
            }
            else
            {
                return;
            }

            var copyCidChannels = this.cidChannels;

            foreach (var pair in copyCidChannels)
            {
                pair.Value.Dispose();
            }

            copyCidChannels.Clear();

            foreach (var pair in this.Connections)
            {
                pair.Value.Dispose();
            }

            this.Connections.Clear();

            this.UDPConnection.Dispose();
            this.UDPConnection = null;
        }
Esempio n. 2
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "EpicsClient" /> class.
        ///   Constructor
        /// </summary>
        public EpicsClient()
        {
            this.ExceptionContainer = new EpicsExceptionList();
            this.Config             = new EpicsClientConfig();

            this.Codec         = new EpicsClientCodec(this);
            this.UDPConnection = new EpicsClientUDPConnection(this);

            try
            {
                this.UDPBeaconConnection = new EpicsClientUDPConnection(this, this.Config.UDPBeaconPort);

                this.beaconChecker = new Thread(this.checkBeacons);
                this.beaconChecker.IsBackground = true;
                this.beaconChecker.Start();

                // The first 30 seconds is init-phase. New iocs will not be handled.
                ThreadPool.QueueUserWorkItem(
                    delegate
                {
#if DEBUG
                    Thread.Sleep(250);
                    this.startupRunning = false;
#else
                    // Thread.Sleep(31 * 1000);
                    Thread.Sleep(1 * 1000);
                    this.startupRunning = false;
#endif
                });
            }
            catch (SocketException ex)
            {
                this.ExceptionContainer.Add(new Exception("BeaconHandling deactivated due to blocked Port"));
            }
            catch (Exception e)
            {
                this.ExceptionContainer.Add(e);
            }

            this.searchHandler = new Thread(this.SearchHandler);
            this.searchHandler.IsBackground = true;
            this.searchHandler.Start();
        }