Пример #1
0
        /// <summary>
        /// Callback used by StreamReader when a read finishes
        /// </summary>
        /// <param name="task"></param>
        private void OnAsyncRead(Task <String> task)
        {
            try
            {
                if (task.Exception == null && task.Result != null)
                {
                    lock (streamReader.BaseStream)
                    {
                        streamReader.ReadLineAsync().ContinueWith(OnAsyncRead);
                    }
                }
                else if (task.Result == null)
                {
                    throw new System.IO.EndOfStreamException();
                }
                else
                {
                    throw task.Exception;
                }

                if (OnRawMessageReceived != null)
                {
                    foreach (var d in OnRawMessageReceived.GetInvocationList())
                    {
                        Task.Run(() => d.DynamicInvoke(this, task.Result));
                    }
                }
            }
            catch (Exception e)
            {
                Exception = e;
                if (OnException != null)
                {
                    foreach (var d in OnException.GetInvocationList())
                    {
                        var task2 = Task.Run(() => d.DynamicInvoke(this, e));
                    }
                }
            }
            finally
            {
            }
        }