UdpClient.EndSend(IAsyncResult) 方法

定义

结束挂起的异步发送。

public:
 int EndSend(IAsyncResult ^ asyncResult);
public int EndSend(IAsyncResult asyncResult);
member this.EndSend : IAsyncResult -> int
Public Function EndSend (asyncResult As IAsyncResult) As Integer

参数

asyncResult
IAsyncResult

IAsyncResult由对 .. 的调用BeginSend返回的对象。

返回

如果成功,则发送到 <a0/> 的字节数。

例外

asyncResultnull

EndSend(IAsyncResult) 以前为异步读取调用过。

尝试访问基础套接字时出错。

基础 Socket 已关闭。

示例

下面的代码示例用于 BeginSend 完成服务器请求的异步发送。

public static bool messageSent = false;

public static void SendCallback(IAsyncResult ar)
{
    UdpClient u = (UdpClient)ar.AsyncState;

    Console.WriteLine($"number of bytes sent: {u.EndSend(ar)}");
    messageSent = true;
}

注解

此方法会阻止操作完成。

若要同步执行此操作,请使用 Send 该方法。

适用于