none
System.IO.IOException: The semaphore timeout period has expired for NamedPipeClientStream.Connect

    Question

  •   const int CONNECTTIMEOUT = 100;
      const int WRITE_RETRY = 5;
      for (var i = 0; i < WRITE_RETRY; i++)
      {
    try
    {
     using (var writePipe = new NamedPipeClientStream(PIPE_INTEGRATION2PLUGIN))
     {
    var ss = new StreamString(writePipe);

    writePipe.Connect(CONNECTTIMEOUT);

    ss.WriteString(message);

    writePipe.Flush();

    writePipe.Close();

    return true;
     }
    }
    catch (Exception e)
    {
     Console.WriteLine("Exception in SendToServerPipe(): " + e.GetType()  + ": "+ e.Message);
    }
      }

    The writePipe.Connect(CONNECTTIMEOUT) method throws "System.IO.IOException: The semaphore timeout period has expired" exception in some PC's.

    I have searched a lot on this topic related to named pipes..but no help

    Can anybody help ?

    Thursday, March 14, 2013 12:57 PM

Answers

  • YOu looping and exception handling can create issues.  You can't connect to the same device more than once.  You also have problems when you do get an exception you don't close the connection and stream.  I suspect the reties are causing the error and recommend that you find a better way of doing the retires.  I atempted to clean up your code, but I'm not sure how to impliment the 4 retries.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO.Pipes;
    namespace ConsoleApplication3
    {
        class Program
        {
            static void Main(string[] args)
            {
            }
            static Boolean test()
            {
                Boolean results = false;
                NamedPipeClientStream writePipe = null;
                string message = "";
                const int CONNECTTIMEOUT = 100;
                const int WRITE_RETRY = 5;
                try
                {
                        writePipe = new NamedPipeClientStream(PIPE_INTEGRATION2PLUGIN);
                        writePipe.Connect(CONNECTTIMEOUT);
                        for (int i = 0; i < WRITE_RETRY; i++)
                        {
                            using (writePipe)
                            {
                                var ss = new StreamString(writePipe);
                                ss.WriteString(message);
                                results =  true;
                            }
                        }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception in SendToServerPipe(): " + e.GetType() + ": " + e.Message);
                }
                finally
                {
                     writePipe.Flush();
                     writePipe.Close();
                }
                   return results;
            }
        }
    }


    jdweng

    Thursday, March 14, 2013 2:09 PM

All replies

  • It means the CONNECTIONTIMEOUT number of milliseconds has expired with nobody waiting for the connection on the server side.   Do you have a server running  (i.e., some code using NamedPipeServerStream.WaitForConnection)?

    Thursday, March 14, 2013 2:09 PM
  • YOu looping and exception handling can create issues.  You can't connect to the same device more than once.  You also have problems when you do get an exception you don't close the connection and stream.  I suspect the reties are causing the error and recommend that you find a better way of doing the retires.  I atempted to clean up your code, but I'm not sure how to impliment the 4 retries.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO.Pipes;
    namespace ConsoleApplication3
    {
        class Program
        {
            static void Main(string[] args)
            {
            }
            static Boolean test()
            {
                Boolean results = false;
                NamedPipeClientStream writePipe = null;
                string message = "";
                const int CONNECTTIMEOUT = 100;
                const int WRITE_RETRY = 5;
                try
                {
                        writePipe = new NamedPipeClientStream(PIPE_INTEGRATION2PLUGIN);
                        writePipe.Connect(CONNECTTIMEOUT);
                        for (int i = 0; i < WRITE_RETRY; i++)
                        {
                            using (writePipe)
                            {
                                var ss = new StreamString(writePipe);
                                ss.WriteString(message);
                                results =  true;
                            }
                        }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception in SendToServerPipe(): " + e.GetType() + ": " + e.Message);
                }
                finally
                {
                     writePipe.Flush();
                     writePipe.Close();
                }
                   return results;
            }
        }
    }


    jdweng

    Thursday, March 14, 2013 2:09 PM