Example #1
0
            private void eventHandling__dataDistributionTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                try
                {
                    this._dataDistributionTimer.Stop();

                    SocketData dataToBeSend = null;

                    if (this._TCPUnicastDataDistributionQueue.Count > 0)
                    {
                        lock (this._TCPUnicastDataDistributionQueue)
                        {
                            try
                            {
                                dataToBeSend = (SocketData)this._TCPUnicastDataDistributionQueue.Dequeue();
                            }
                            catch (Exception ex)
                            {
                                CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString());
                                dataToBeSend = null;
                            }
                        }

                        if (!(dataToBeSend == null))
                        {
                            IEnumerator         enumm  = default(IEnumerator);
                            SocketsServerClient client = default(SocketsServerClient);

                            lock (this._TCPSocketsServerClientsTable)
                            {
                                try
                                {
                                    enumm = this._TCPSocketsServerClientsTable.GetEnumerator();
                                    while (enumm.MoveNext())
                                    {
                                        try
                                        {
                                            client = (SocketsServerClient)(((DictionaryEntry)enumm.Current).Value);

                                            //verifies if the client is valid to send data
                                            if (!this._DisconnectedTCPsocketServerClientsTable.ContainsKey(client.ClientID))
                                            {
                                                try
                                                {
                                                    client.SendDataToServer(dataToBeSend);
                                                }
                                                catch (Exception ex)
                                                {
                                                    CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString());
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString());
                                        }
                                        Thread.Sleep(1);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString());
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    CustomEventLog.WriteEntry(ex);
                }
                finally
                {
                    if (this._TCPUnicastDataDistributionQueue.Count > 0)
                    {
                        this._dataDistributionTimer.Start();
                    }
                }
            }