Esempio n. 1
0
        public void Complete()
        {
            if (Conn != null)
            {
                Conn.OnReceive -= Conn_OnReceive;
                OnComplete?.Invoke();

                foreach (var handler in OnReceive?.GetInvocationList())
                {
                    OnReceive -= (MWEventHandler <Message>)handler;
                }
                foreach (var handler in OnComplete?.GetInvocationList())
                {
                    OnComplete -= (MWEventHandler)handler;
                }

                InternalComplete();
            }
        }
Esempio n. 2
0
        private void invokeOnReceive(string msg)
        {
            if (OnReceive == null)
            {
                return;
            }

            try
            {
                var members = OnReceive.GetInvocationList().Cast <Func <string, Task> >();

                Task.WhenAll(members.Select(x => x(msg)))
                .ContinueWith(t => InvokeOnError(t.Exception), TaskContinuationOptions.OnlyOnFaulted);
                //.Wait(0); //throws TaskCanceledException -> why ?
            }
            catch (Exception ex) when(ex.InnerException is TaskCanceledException)
            {
            }
        }
Esempio n. 3
0
        private void invokeOnReceive(string msg)
        {
            if (OnReceive == null)
            {
                return;
            }

            try
            {
                var members = OnReceive.GetInvocationList().Cast <Func <string, Task> >();

                var list = members.Select(x => x(msg)).ToList();
                Task.WaitAll(list.ToArray());

                bool allFaulted = !list.Where(t => !t.IsFaulted).Any();
                if (allFaulted)
                {
                    InvokeOnError(list[0].Exception);
                }
            }
            catch (Exception ex) when(ex.InnerException is TaskCanceledException)
            {
            }
        }