Problem on Threading and TcpListen

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cylix

    #1

    Problem on Threading and TcpListen

    I have a tcpListen on a new thread in my application.
    When start the tcpListen, the process will hold in that line.
    I would like to terminate the tcpListen by abort the thread, but fail.

    How can I abost the tcpListen in a indepent thread?

    Thanks a lot!

  • Tom Shelton

    #2
    Re: Problem on Threading and TcpListen


    Cylix wrote:
    I have a tcpListen on a new thread in my application.
    When start the tcpListen, the process will hold in that line.
    I would like to terminate the tcpListen by abort the thread, but fail.
    >
    How can I abost the tcpListen in a indepent thread?
    >
    Thanks a lot
    The reason you can't use Thread.Abort is that Thread.Abort is a request
    to the thread to shutdown at the earlieast possible moment. If that
    thread happens to be in Unmanaged code (as it is, while the socket is
    in a listening state - ie a call to accept), it will not recieve that
    request (a threadabortexce ption) until it returns from that call. So,
    unless a client happens to connect you won't abort.

    So, the common way to overcome that is to make sure you have a
    reference to the actual listener, and then call close on it. This will
    cause it to leave the listen state and then you can shutdown the
    thread.

    --
    Tom Shelton

    Comment

    • GraGra33

      #3
      Re: Problem on Threading and TcpListen

      I have some code that can point you in the right direction. Email me and
      I'll send it to you...

      "Cylix" <cylix2000@gmai l.comwrote in message
      news:1169800108 .458128.72870@q 2g2000cwa.googl egroups.com...
      >I have a tcpListen on a new thread in my application.
      When start the tcpListen, the process will hold in that line.
      I would like to terminate the tcpListen by abort the thread, but fail.
      >
      How can I abost the tcpListen in a indepent thread?
      >
      Thanks a lot!
      >

      Comment

      Working...