Where do I handle asynchronous exceptions?

前端 未结 2 558
别那么骄傲
别那么骄傲 2021-02-08 14:42

Consider the following code:

class Foo {
    // boring parts omitted

    private TcpClient socket;

    public void Connect(){
        socket.BeginConnect(Host,         


        
2条回答
  •  春和景丽
    2021-02-08 14:54

    If the process of accepting a connection results in an error your cbConnect method will be called. To complete the connection though you'll need to make the following call

    socket.EndConnection(result);
    

    At that point the error in the BeginConnect process will be manifested in a thrown exception.

提交回复
热议问题