private void SendCachedMessage()
 {
     while (true)
     {
         Message message;
         lock (_sendingMsgCache) {
             while (_sendingMsgCache.Count <= 0)
             {
                 Monitor.Wait(_sendingMsgCache);
             }
             message = _sendingMsgCache[0];
             _sendingMsgCache.RemoveAt(0);
         }
         var service = _service;
         if (service != null)
         {
             int sendingResult = service.SendMessage(new NetworkfMessage(message));
             if (sendingResult == -1)
             {
                 var eventArgs = new NetworkEventCaughtEventArgs()
                 {
                     message = "A network error occured during sending data."
                 };
                 OnEventCaught(eventArgs);
             }
         }
     }
 }
        private void OnServiceTeardown()
        {
            var service = _service;

            _service                   = null;
            service.parseMessage       = null;
            service.OnMessageReceived -= OnMessageReceived;
            service.OnServiceTeardown -= OnServiceTeardown;
            var eventArgs = new NetworkEventCaughtEventArgs()
            {
                message = "Connection is closed."
            };

            OnEventCaught(eventArgs);
        }
Example #3
0
		protected void OnEventCaught(NetworkEventCaughtEventArgs args) {
			if (EventCaught != null) EventCaught(this, args);
		}