Example #1
0
        void InitiateClosingServiceInstance()
        {
            InstanceContext serviceInstance = OperationContext.Current.InstanceContext;

            serviceInstance.BeginClose(ListenerConstants.RegistrationCloseTimeout,
                                       Fx.ThunkCallback(new AsyncCallback(CloseCallback)), serviceInstance);
        }
Example #2
0
        void CloseInitiate(TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            InstanceContext[] instances = this.ToArray();
            for (int index = 0; index < instances.Length; index++)
            {
                InstanceContext instance = instances[index];
                try
                {
                    if (instance.State == CommunicationState.Opened)
                    {
                        IAsyncResult result = instance.BeginClose(timeoutHelper.RemainingTime(), Fx.ThunkCallback(new AsyncCallback(CloseInstanceContextCallback)), instance);
                        if (!result.CompletedSynchronously)
                        {
                            continue;
                        }
                        instance.EndClose(result);
                    }
                    else
                    {
                        instance.Abort();
                    }
                }
                catch (ObjectDisposedException e)
                {
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                }
                catch (InvalidOperationException e)
                {
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                }
                catch (CommunicationException e)
                {
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                }
                catch (TimeoutException e)
                {
                    if (TD.CloseTimeoutIsEnabled())
                    {
                        TD.CloseTimeout(e.Message);
                    }
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                }
            }
        }