Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6766473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:50:06+00:00 2026-05-26T14:50:06+00:00

I am developing a windows service application and I’m running into a problem concerning

  • 0

I am developing a windows service application and I’m running into a problem concerning named pipe server.
The service application has a named pipe service, in order for the GUI to communicate with it – and the GUI has a named pipe client.

When I run the console version of my app (same code but initialized in a console project), everything works fine, but when I run the service version of the app (either installed using setup project or using VS unistallUtil.exe) I get this error:

System.OperationCanceledException: The operation was canceled.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.Pipes.NamedPipeServerStream.EndWaitForConnection(IAsyncResult asyncResult)
   at Common.PipeCommunication.SomePipeServer.ClientConnected(IAsyncResult ar) in SomePipeServer.cs:line 80

This error occurs when I start the service, not even attempting to connect the client to it. Here is my PipeServer Class:

public class SomePipeServer
{

    #region PRIVATE VARIABLES
    private string                  _pipeName = "SomePipeServer";
    private NamedPipeServerStream   _pipeServer;
    private IAsyncResult            _connectRequest;
    private byte[] oBuffer;  
    #endregion


    #region PUBLIC VARIABLES
    public event EventHandler MsgReceived;
    #endregion


    #region PUBLIC METHODS
    public SomePipeServer()
    {
        oBuffer = new byte[4096]; 
    }

    public void Start() 
    {
        try
        {
            _pipeServer = new NamedPipeServerStream(
                _pipeName, PipeDirection.InOut, -1,
                PipeTransmissionMode.Message,
                PipeOptions.Asynchronous);

            _connectRequest = _pipeServer.BeginWaitForConnection(
                ClientConnected, null);
        }
        catch (Exception ex)
        {
            ...
        }
    }
    public void Stop()
    {
        try
        {
            _connectRequest = null;

            if (_pipeServer == null)
                return;

            if (_pipeServer.IsConnected)
                _pipeServer.Disconnect();

            //_pipeServer.Close();
        }
        catch (Exception ex)
        {
            ...
        }
    }
    #endregion


    #region PRIVATE METHODS
    private void ClientConnected(IAsyncResult ar)
    {
        try
        {
            if (ar != null)
            {
                _pipeServer.EndWaitForConnection(ar); //line 80
                _connectRequest = null;
                _connectRequest = _pipeServer.BeginRead(oBuffer, 0, 4096,
                    ClientMessage, null);

            }
        }
        catch (Exception ex)
        {
            ...
        }
    }
    private void ClientMessage(IAsyncResult ar)
    {
        try
        {
            if (ar != null)
            {
                _pipeServer.EndRead(ar);

                string message = System.Text.ASCIIEncoding.ASCII.GetString(oBuffer).Trim(new char[] { '\0', ' ' });
                message = message.Replace(Environment.NewLine, " ").TrimEnd();

                OnReceive(message);

                _connectRequest = null;
                //_connectRequest = _pipeServer.BeginRead(oBuffer, 0, 4096,
                //    new AsyncCallback(ClientMessage), null);

                //_pipeServer.Disconnect();
                //_pipeServer.BeginWaitForConnection(ClientConnected, null);
                Stop();
                Start();
            }
        }
        catch (Exception ex)
        {
            ...
        }
    }
    private void OnReceive(string in_msg)
    {
        if (MsgReceived != null)
        {
            MsgReceived(in_msg, EventArgs.Empty);
        }
    }
    #endregion
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:50:07+00:00Added an answer on May 26, 2026 at 2:50 pm

    There is a discussion on this MSDN page about (what I’ve understood) the same problem that you have.

    Windows will complete all overlapped I/O for a thread that has exited, with ERROR_OPERATION_ABORTED.

    IAsyncResult does not necessarily imply overlapped I/O, but it is a
    natural fit, and it seems to be the method used by named pipes.

    In this case, I would recommend having your main thread create the
    named pipes; this is normal for a named pipe server (having a separate
    thread just to create the named pipes is not).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing large data collecting ASP.Net/Windows service application-pair that uses Microsoft SQL Server
I am developing c# application, which is running as a windows service. What ever
I'm developing and application that runs as a Windows service. There are other components
I'm developing an application to achieve work in background through a Windows Service. I've
I'm getting close to desperate.. I am developing a field service application for Windows
I'm developing an application that's going to be implemented as a Windows Service and
I'm developing a Windows Mobile application that uses Bing Maps Web Service to show
I am developing a Windows Service application of some complexity, and need to have
I've been developing a remote desktop application which runs as a Windows service, and
I'm developing a Windows Service in VB.NET 2008, but I feel like I'm going

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.