Exemplo n.º 1
0
        public void StopListening()
        {
            using (EneterTrace.Entering())
            {
                using (ThreadLock.Lock(myListeningManipulatorLock))
                {
                    try
                    {
                        ListeningInstance.StopListening(myPipeName, myPipeServerListeners);
                    }
                    catch
                    {
                    }

                    myPipeServerListeners.Clear();
                }
            }
        }
Exemplo n.º 2
0
        public void StartListening(Action <Stream> messageHandler)
        {
            using (EneterTrace.Entering())
            {
                using (ThreadLock.Lock(myListeningManipulatorLock))
                {
                    if (IsListening)
                    {
                        string aMessage = TracedObject + ErrorHandler.IsAlreadyListening;
                        EneterTrace.Error(aMessage);
                        throw new InvalidOperationException(aMessage);
                    }

                    try
                    {
                        for (int i = 0; i < myNumberOfInstances; ++i)
                        {
                            ListeningInstance aListeningInstance = new ListeningInstance(myPipeName, myNumberOfInstances, myPipeSecurity);
                            myPipeServerListeners.Add(aListeningInstance);

                            aListeningInstance.StartListening(messageHandler);
                        }
                    }
                    catch (Exception err)
                    {
                        EneterTrace.Error(TracedObject + ErrorHandler.FailedToStartListening, err);

                        try
                        {
                            // Clear after failed start
                            StopListening();
                        }
                        catch
                        {
                            // We tried to clean after failure. The exception can be ignored.
                        }

                        throw;
                    }
                }
            }
        }