How to end a Socket.BeginAccept call

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

    How to end a Socket.BeginAccept call

    When closing down my server I get the following exception


    An unhandled exception of type 'System.Invalid OperationExcept ion' occurred
    in system.dll

    Additional information: AcceptCallback


    I beleive that it is the asynchronous BeginAccept call which causes the
    problem. How can I avoid this? Here is the code:

    private void ListenForClient s()
    {
    listener = new Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
    ProtocolType.Tc p);
    listener.Bind(n ew IPEndPoint(IPAd dress.Any, 9123));
    listener.Listen (10);

    listener.BeginA ccept(new AsyncCallback(t his.OnAccept), listener);
    Invoke(new UpdateEventList Delegate(Update EventList), new object[] {
    "Listening for clients..." } );
    }

    private void radioButtonStop ped_CheckedChan ged(object sender,
    System.EventArg s e)
    {
    if (radioButtonSto pped.Checked == true)
    {
    Invoke(new UpdateEventList Delegate(Update EventList), new object[] {
    "Closing server..." } );
    listener.Close( );
    listeningThread .Abort();
  • Joachim

    #2
    RE: How to end a Socket.BeginAcc ept call

    Is it not possible???

    "Joachim" wrote:
    [color=blue]
    > When closing down my server I get the following exception
    >
    >
    > An unhandled exception of type 'System.Invalid OperationExcept ion' occurred
    > in system.dll
    >
    > Additional information: AcceptCallback
    >
    >
    > I beleive that it is the asynchronous BeginAccept call which causes the
    > problem. How can I avoid this? Here is the code:
    >
    > private void ListenForClient s()
    > {
    > listener = new Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
    > ProtocolType.Tc p);
    > listener.Bind(n ew IPEndPoint(IPAd dress.Any, 9123));
    > listener.Listen (10);
    >
    > listener.BeginA ccept(new AsyncCallback(t his.OnAccept), listener);
    > Invoke(new UpdateEventList Delegate(Update EventList), new object[] {
    > "Listening for clients..." } );
    > }
    >
    > private void radioButtonStop ped_CheckedChan ged(object sender,
    > System.EventArg s e)
    > {
    > if (radioButtonSto pped.Checked == true)
    > {
    > Invoke(new UpdateEventList Delegate(Update EventList), new object[] {
    > "Closing server..." } );
    > listener.Close( );
    > listeningThread .Abort();[/color]

    Comment

    • Ashly

      #3
      RE: How to end a Socket.BeginAcc ept call

      I Think You Have To unsubscribe all The subscribed values to the delegate By Using -= and then close it......it's Not Checked..But It hink so

      From http://www.developmentnow.com/g/36_2...ccept-call.htm

      Posted via DevelopmentNow. com Groups
      DevelopmentNow is an award-winning creative software development agency integrating mobile, web, hardware, mixed reality, and emerging technology.

      Comment

      Working...