locked
closing udp connection forcebly RRS feed

  • Question

  • i've a udpclient to receive messages, which runs on a separate thread. when application shutsdown i want this udpclient gets closed and thread exists, here's my code

    function ran using thread

    void startClient()
            {          
                 cl = new UdpClient(_currentPort);          
                try
                {               
                    while (_isON)
                    {
                        IPEndPoint ipe = new IPEndPoint(IPAddress.Any, 0);
                        byte[] data = cl.Receive(ref ipe);
                    }
               }
    }
    
    
    


    Code to Close Thread

    private void button2_Click_1(object sender, EventArgs e)
            {
                _isON = false;           
                cl.Close();
                thdClient.Abort();
                thdClient.Join();
                Application.Exit();            
            }
    


    But this throws an Exception "Thread was being Aborted".

    I think that's the exception thrown by thread.Abort() method.

    How can i supress this exception?


    Regards Kumar Gaurav.
    • Moved by Mike Feng Monday, October 31, 2011 4:19 AM C# (From:Visual Basic General)
    • Moved by Leo Liu - MSFT Tuesday, November 1, 2011 2:44 AM Moved for better support. (From:Visual C# General)
    Sunday, October 30, 2011 2:38 PM

All replies

  • Hi Kumar,

    Welcome to the MSDN Forum.

    Based on your description, it seems that your code is in C#, so I moved this thread to C# forum for better support.

    Best regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, October 31, 2011 4:19 AM