INotificationTransport::DrainNotifications メソッド
このメソッドを呼び出すと、送信キューに入っている通知が処理されるのを待ったり、送信キューに入っている通知の数を調べたりすることができます。
構文
HRESULT DrainNotifications(
long WaitTime,
long *PendingCount
)
パラメータ
- WaitTime
[入力] 保留中の通知が処理されるのを待つ時間 (秒) です。このメソッドは、指定した時間が経過すると呼び出しから復帰します。呼び出し側は、メソッドが復帰するまでブロックされます。WaitTime を -1 に設定すると、メソッドはすぐに復帰し、保留中の通知の数が PendingCount パラメータを介して戻されます。WaitTime を 0 に設定すると、送信キューが空になるまでメソッドは復帰しません。 - PendingCount
[出力] メソッドが復帰した時点での送信キューに入っている保留中の通知の数です。
戻り値
S_OK | 呼び出しは正常に行われました。 |
E_UNEXPECTED | 前の呼び出しがまだ保留中のときにこのメソッドが呼び出されました。同時に複数の DrainNotifications を呼び出すことはできません。 |
ここに示すリターン コードの他に、Microsoft® .NET Alerts クライアント ライブラリのメソッドによって、標準の Win32 または Component Object Model (COM) の結果コードがシステムの下位層から返される場合があります。Microsoft Visual Studio® のエラー照合ツールを使用すると、これらの標準結果コードに関連付けられたヘルプ テキストを表示できます。
例
次の例は、DrainNotifications の使い方を示しています。
void DemoDrainNotifications(INotificationTransport *pITransport) {
HRESULT hr;
long lWaitTime;
long lPendingCount;
// Query the number of alerts in the transmission queue.
lWaitTime = 1-;
hr = pITransport->DrainNotifications(lWaitTime, &lPendingCount;);
if (FAILED(hr)) goto error; // Jumps to error handler at the end of the function body.
wcout endl endl L"Number of alerts waiting to be sent:" lPendingCount;
// Drain any alerts in the transmission queue for 10 seconds.
lWaitTime = 10;
hr = pITransport->DrainNotifications(lWaitTime, &lPendingCount;);
if (FAILED(hr)) goto error; // Jumps to error handler at the end of the function body.
wcout endl endl L"After draining alerts for " lWaitTime L" seconds, " endl
L"the number of alerts still waiting to be sent is:" lPendingCount;
// Drain all alerts in the transmission queue.
lWaitTime = 0;
hr = pITransport->DrainNotifications(lWaitTime, &lPendingCount;);
if (FAILED(hr)) goto error; // Jumps to error handler at the end of the function body.
wcout endl endl L"All alerts have been drained from the transmission queue.The value of "
endl L"lPendingCount is:" lPendingCount;
return;
error:
wcout endl L"DrainNotifications failed with error code:" hr L" (0x" hex hr L")";
ShowErrorMessage(hr);
return;
} // End DemoDrainNotifications.
解説
トランスポート オブジェクトを使用して非同期モードで通知を送信した場合は、DrainNotifications を呼び出して、送信キューに通知が存在しないことを確認してから、トランスポート オブジェクトを破棄するようにしてください。
複数のスレッドから通知を送信する場合は、現在通知を送信しようとしているスレッドが他に存在しないことを確認してから DrainNotifications を呼び出してください。
関連項目
|