Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageReceiver"/> class.
 /// </summary>
 /// <param name="networkStream">The network stream.</param>
 /// <exception cref="ArgumentNullException">
 /// Thrown if the specified value is null:
 /// networkStream - The value must not be null.
 /// </exception>
 public MessageReceiver(NetworkStream networkStream)
 {
     this.networkStream             = networkStream ?? throw new ArgumentNullException(nameof(networkStream), "The value must not be null.");
     this.messageReceiverThreadArgs = new MessageReceiverThreadArgs();
     this.messageReceiverThread     = new Thread(this.Worker);
     this.formatter = new BinaryFormatter();
 }
Пример #2
0
        /// <summary>
        /// Works the specified data.
        /// </summary>
        /// <param name="data">The specified data.</param>
        private void Worker(object data)
        {
            MessageReceiverThreadArgs args = (MessageReceiverThreadArgs)data;

            while (!args.Stop)
            {
                ////try
                ////{

                MessageContainer messageContainer = (MessageContainer)this.formatter.Deserialize(this.networkStream);
                this.FireMessageReceived(this, new MessageReceivedEventArgs(messageContainer.Content));

                ////}
                ////catch
                ////{
                //// TODO: do something.
                ////throw;
                ////}

                ////Thread.Sleep(args.PollDelay);
            }
        }