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 8724171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:46:23+00:00 2026-06-13T07:46:23+00:00

I am writing a program calls APPLICATION A for the sake of simplicity which

  • 0

I am writing a program calls “APPLICATION A” for the sake of simplicity which opens a socket connection to port 8881 on local host; later it spawns an exe application call “APPLICATION B” using the code blow:

        try
        {
            XmSam.Log("Spawning (" + process + ")");

            ProcessEx proc = new ProcessEx();

            proc.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + process + ".exe";
            proc.StartInfo.Arguments = parameters;
            proc.StartInfo.UseShellExecute = false;
            proc.Start();

            Program.Processes.Add(proc);

            XmSam.Log("Spawned " + proc.ProcessName);
        }
        catch (Exception ex)
        {
            XmSam.Log(ex);
        }

When I turn off APPLICATION A (either by stop the application or kill its process in window task manager), the APPLICATION B still runs which is fine. However, when I started APPLICATION A again I got the exception:

2012-10-18 16:21:23 - Only one usage of each socket address (protocol/network address/port) is normally permitted
2012-10-18 16:21:23 -    at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)

This error occured when APPLICATION A tried to open the socket to port 8881. This error would go away if I kill APPLICATION B. I don’t think it is because of APPLICATION B code because it has nothing such as the below code shows:

    [STAThread]
    static void Main()
    {
        while (true)
        {
        }
    }

I tried to look at MSDN under Process class but I did not see anything about this. I assumed when you spawned a process, that process is independent to the invocation application but apparently that is not the case. Do you know of any setting that let me spawn a process without having it holding onto the invocation application?

I know another way is to have code in APPLICATION A to kill APPLICATION B but that is not the idea solution especially in the case of APPLICATION A crashes unexpectedly.

Thank you.

  • 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-06-13T07:46:24+00:00Added an answer on June 13, 2026 at 7:46 am

    I found the answer after more digging around. I find this excellent article

    In it, the main explanation for this issue is as follow:

    System.Diagnostics.Process.Start causes the child process to inherit handles from the parent process. That means, whatever process you spawn (e.g. Internet Explorer), that process gets all of the handles owned by your process! So even if you free up handles in your process, if the process you spawned is still running, your handles won’t really be freed because the child process is supposedly using them.

    So with that in mind, all I have to do is to update my UseShellExecute flag to true.

    proc.StartInfo.UseShellExecute = true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a c# application which uses automation to control another program. Naturally that
I'm writing a java application which runs on the local machine, it needs to
I'm writing an application with a Java GUI which calls some FORTRAN code. I
I'm writing a small JavaScript program that makes web calls to pull up weather
We are writing an application which provides a RESTful API. The application needs to
I'm writing a C# application that calls a C++ dll. This dll is a
I'm writing a console application which is looking up information about SSIS packages in
I am writing an application which has a JLayeredPane (call it layers) containing two
I am writing an command line application in C and from within the program,
I'm writing a Haskell program which generates an XML file. Apparently it is considered

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.