語言

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。

傳回

若成功,傳送至 UdpClient.

例外狀況

asyncResult 是 null。

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 方法。

適用於