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

  • Home
  • SEARCH
  • 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 8363043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:05:06+00:00 2026-06-09T12:05:06+00:00

I have written a TCP server application in c#. Application listens for inbound connections

  • 0

I have written a TCP server application in c#. Application listens for inbound connections

using TcpListener.AcceptTcpClient() method in main listener thread.

When a connection is received, TcpListener.AcceptTcpClient() unblocks and returns TCPClient object.

On receiving a connection, a new thread is created and started to read write data to new connection.

The new thread is started by following code.

while(true)
{
  TcpClient client = serverListener.AcceptTcpClient();


  if (client.Connected)
  {
    Thread t = new Thread(delegate() { readWriteData(client); });
    t.IsBackground = true;
    t.Start(); /// Problem happens here. The thread gets stuck here and doesn't move   further
  }
 }

The application runs fine but in some times in Windows 7 machines, the application suddenly stops listening for tcp connections.

On analysis of thread stacks of application in this state, ( Microsoft stack explorer was used to view stacks of all threads of the application ) it is found that the main listener thread is stuck on following line of the code section shown above

 t.Start(); /// Problem happens here. The thread gets stuck here and doesn't move   further

I did lot of research and couldn’t find why it is happening. This behavior is observed only in windows 7 systems.

Can anybody please help me to solve this issue.

As suggested by Rob,

I am posting here stack trace shown by windbg (sos)

0547eae0 7282e006 mscorwks!Thread::StartThread+0xc3, calling mscorwks!_EH_epilog3
0547eb00 727ac825 mscorwks!__SwitchToThread+0xd, calling mscorwks!__DangerousSwitchToThread
0547eb10 728b9c6f mscorwks!ThreadNative::StartInner+0x1ba, calling mscorwks!__SwitchToThread
0547eb58 727e4b04 mscorwks!SafeHandle::DisposeNative+0x3a, calling mscorwks!LazyMachStateCaptureState
0547ebc8 728b9d80 mscorwks!ThreadNative::Start+0xa6, calling mscorwks!ThreadNative::StartInner
0547ec18 728b9d01 mscorwks!ThreadNative::Start+0x1f, calling mscorwks!LazyMachStateCaptureState
0547ec74 71de6afc (MethodDesc 0x71c13048 +0x8c System.Threading.Thread.Start()), calling mscorwks!ThreadNative::Start
0547ec8c 030e2a46 (MethodDesc 0x30da408 +0x25e WindowsService.Server.startListener()), calling (MethodDesc 0x71c13048 +0 System.Threading.Thread.Start())
  • 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-09T12:05:07+00:00Added an answer on June 9, 2026 at 12:05 pm

    I think I have figured out the issue.

    I did close an open handle in another thread by mistake. I was closing same handle two times in a thread by using native close method via pinvoke. It might have happened that after first close of the handle, the same handle was assigned some where internal in process. After that second close was executed but it actually closed the open handle hence that led to unexplained unsuitability in the process.

    After removing that second close, the issue didn’t appear again.

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

Sidebar

Related Questions

I have written a TCP server implementation using which I created an application which
I have written a C# server which listens for Tcp connections. A client can
I have written a Python TCP/IP server for internal use, using win32serviceutil/py2exe to create
I have a client/server application written in delphiXe2 using Indy TIdTCPServer and TIdTCPClient that
I currently have a TCP server application written in .Net that receives and submits
I have a TCP/IP server written in C# .net which can have 10,000 connections
I have written a TCP server using the Socket class's asynchronous/IOCP methods, BeginSend()/BeginRead()/etc. I
I have a TCP server app that is written in C#. I accept TCP
I have a client/server program in TCP written in C, and I would like
I have a Client/Server application written Delphi. Essentially all the application is doing is

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.