Пример #1
0
        public string Receive()
        {
            string message = "";

            message = ConnectionReceive.ReadLine();

            return(message);
        }
Пример #2
0
        public int Disconnect()
        {
            ConnectionStatus = 4;

            try
            {
                ConnectionReceive.Close();
                ConnectionSend.Close();
                ConnectionSocket.Close();
                ConnectionStatus = 0;
            }
            catch (Exception e)
            {
                ConnectionStatus = 2;
            }

            return(0);
        }
Пример #3
0
        void _CallOut()
        {
            while (true)
            {
                try
                {
                    object[] cb = null;
                    lock (_CallOutQueue)
                        if (_CalloutThread == System.Threading.Thread.CurrentThread)
                        {
                            if (_CallOutQueue.Count > 0)
                            {
                                cb = _CallOutQueue.Dequeue();
                            }
                            else
                            {
                                System.Threading.Monitor.Wait(_CallOutQueue, 30000);

                                if (_CallOutQueue.Count == 0)
                                {
                                    if (_CalloutThread == System.Threading.Thread.CurrentThread)
                                    {
                                        _CalloutThread = null;
                                        return;
                                    }
                                }
                            }
                        }
                        else
                        {
                            return;
                        }

                    if (cb != null)
                    {
                        if (cb[0] is ConnectionClosed)
                        {
                            ConnectionClosed c = cb[0] as ConnectionClosed;

                            try
                            {
                                c(this);
                            }
                            catch (Exception ex)
                            {
                                STEM.Sys.EventLog.WriteEntry("Connection.ConnectionClosed", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
                            }
                        }
                        else if (cb[0] is ConnectionOpened)
                        {
                            ConnectionOpened c = cb[0] as ConnectionOpened;
                            try
                            {
                                c(this);
                            }
                            catch (Exception ex)
                            {
                                STEM.Sys.EventLog.WriteEntry("Connection.ConnectionOpened", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
                            }
                        }
                        else if (cb[0] is ConnectionReceive)
                        {
                            ConnectionReceive c = cb[0] as ConnectionReceive;
                            try
                            {
                                c((byte[])cb[1], (int)cb[2], (DateTime)cb[3]);
                            }
                            catch (Exception ex)
                            {
                                STEM.Sys.EventLog.WriteEntry("Connection.ConnectionReceive", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    STEM.Sys.EventLog.WriteEntry("Connection._CallOut", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
                }
            }
        }