Esempio n. 1
0
        private void ReconnectServiceChannel()
        {
            serviceMutex.WaitOne();

            try
            {
                callback = new JobObjectServiceClientCallback();
                callback.OnError += ErrorReceived;
                callback.OnOutput += OutputReceived;
                callback.OnProcessExited += ProcessExited;
                callback.OnServiceMessage += ServiceMessageReceived;

                Context = new InstanceContext(callback);
                HookFaultEvents(Context);

                Factory = new DuplexChannelFactory<IJobObjectService>(Context, configurationName);
                HookFaultEvents(Factory);

                ServiceInstance = Factory.CreateChannel();

                ServiceChannel = ServiceInstance as ICommunicationObject;
                if (ServiceChannel != null)
                {
                    HookFaultEvents(ServiceChannel);
                    ServiceChannel.Open();
                }
            }
            finally
            {
                serviceMutex.ReleaseMutex();
            }
        }
Esempio n. 2
0
        private void CleanupServiceChannel()
        {
            serviceMutex.WaitOne();

            try
            {
                if (callback != null)
                {
                    callback.OnError -= ErrorReceived;
                    callback.OnOutput -= OutputReceived;
                    callback.OnProcessExited -= ProcessExited;
                    callback.OnServiceMessage -= ServiceMessageReceived;
                    callback = null;
                }

                CleanupCommunicationObject(Context);
                Context = null;

                CleanupCommunicationObject(ServiceChannel);
                ServiceChannel = null;
                ServiceInstance = null;

                CleanupCommunicationObject(Factory);
                Factory = null;
            }
            finally
            {
                serviceMutex.ReleaseMutex();
            }
        }