Пример #1
0
        /// <summary>
        /// Initializes the thread to start reading data
        /// </summary>
        protected void StartReceivingMessages()
        {
            _receiveThread = new Thread(() =>
            {
                while (true)
                {
                    do
                    {
                        Message m = MessageUtil.ReadMessage(_client.GetStream());

                        MessageArgs mArgs     = new MessageArgs();
                        mArgs.ReceivedMessage = m;

                        EventHandler <MessageArgs> handler = MessageReceived;
                        handler(this, mArgs);
                    } while (_client.GetStream().DataAvailable);

                    // Make sure to sleap inbetween reading when there is no data available
                    Thread.Sleep(50);
                }
            });

            _receiveThread.Start();
        }
Пример #2
0
        /// <summary>
        /// Initializes the thread to start reading data
        /// </summary>
        protected void StartReceivingMessages()
        {
            _receiveThread = new Thread(() =>
            {
                while (true)
                {
                    do
                    {
                        Message m = MessageUtil.ReadMessage(_client.GetStream());

                        MessageArgs mArgs = new MessageArgs();
                        mArgs.ReceivedMessage = m;

                        EventHandler<MessageArgs> handler = MessageReceived;
                        handler(this, mArgs);

                    } while (_client.GetStream().DataAvailable);

                    // Make sure to sleap inbetween reading when there is no data available
                    Thread.Sleep(50);
                }
            });

            _receiveThread.Start();
        }