NotificationTransportClass.DrainNotifications メソッド
このメソッドを呼び出すと、送信キューに入っている通知の数を調べたり、送信キューに入っている通知を待つことができます。
定義
Public Function DrainNotifications(ByVal lWaitTimeInSec As Integer) As Integer
パラメータ
- IWaitTimeInSec
保留中の通知が処理されるのを待つ時間 (秒) です。このメソッドは、指定した時間が経過すると呼び出しから復帰します。呼び出し側は、メソッドが復帰するまでブロックされます。IWaitTimeInSec を -1 に設定すると、メソッドはすぐに復帰し、保留中の通知の数が返されます。IWaitTimeInSec を 0 に設定すると、送信キューが空になるまでメソッドは復帰しません。
戻り値
メソッドが復帰した時点で送信キューに入っている保留中の通知の数です。
例外
次のエラー値が、System.Runtime.InteropServices.COMException オブジェクトとして、相互運用層から返される場合があります。
0x8000FFFF | 前の呼び出しがまだ保留中のときにこのメソッドが呼び出されました。同時に複数の DrainNotifications を呼び出すことはできません。 |
ここに示すリターン コードの他に、Microsoft® .NET Alerts クライアント ライブラリのメソッドによって、標準の Win32 または Component Object Model (COM) の結果コードがシステムの下位層から返される場合があります。Microsoft Visual Studio® のエラー照合ツールを使用すると、これらの標準結果コードに関連付けられたヘルプ テキストを表示できます。
例
次の例は、DrainNotifications メソッドの使い方を示しています。
Sub DemoDrainNotifications(ByRef Transport As msnotify_interop.NotificationTransportClass)
Dim Wait As Integer
Dim PendingCount As Integer
Try
' Query for the number of alerts in the transmission queue.
Wait = -1
PendingCount = Transport.DrainNotifications(Wait)
Console.WriteLine("There are {0} alerts in the transmission queue.", PendingCount)
Console.WriteLine("")
' Drain any alerts in the transmission queue for 10 seconds.
Wait = 10
PendingCount = Transport.DrainNotifications(Wait)
Console.WriteLine("After draining the queue for {0} seconds, there are {1} {2}", _
Wait, _
PendingCount, _
"alerts in the transmission queue.")
Console.WriteLine("")
' Drain all alerts in the transmission queue.
Wait = 0
PendingCount = Transport.DrainNotifications(Wait)
Console.WriteLine("All alerts have been drained from the transmission queue. {0} {1}", _
"The value of PendingCount (which should be 0) is: ", _
PendingCount)
Console.WriteLine("")
Catch hr As System.Runtime.InteropServices.COMException ' Non-COM exceptions will propagate to Main().
Console.WriteLine("A COM error occurred while calling DrainNotifications: 0x{0} {1}", _
hr.ErrorCode.ToString("x"), _
hr.Message)
End Try
End Sub
解説
トランスポート オブジェクトを使用して非同期モードで通知を送信した場合は、DrainNotifications を呼び出して、送信キューに通知が存在しないことを確認してから、トランスポート オブジェクトを破棄するようにしてください。
関連項目
|