次の方法で共有


NotificationTransportClass.DrainNotifications メソッド

NotificationTransportClass

このメソッドを呼び出すと、送信キューに入っている通知の数を調べたり、送信キューに入っている通知を待つことができます。

定義

public virtual System.Int32 DrainNotifications(System.Int32 IWaitTimeInSec)

パラメータ

  • IWaitTimeInSec
    時間 (秒)。保留中の通知が処理されるのを待つ時間です。このメソッドは、指定した時間が経過すると呼び出しから復帰します。呼び出し側は、メソッドが復帰するまでブロックされます。IWaitTimeInSec を -1 に設定すると、メソッドはすぐに復帰し、保留中の通知の数が返されます。IWaitTimeInSec を 0 に設定すると、送信キューが空になるまでメソッドは復帰しません。

戻り値

メソッドが復帰した時点で送信キューに入っている保留中の通知の数です。

例外

次のエラー値が、System.Runtime.InteropServices.COMException オブジェクトとして、Component Object Model (COM) の相互運用層から返される場合があります。

0x8000FFFF 前の呼び出しがまだ保留中のときにこのメソッドが呼び出されました。同時に複数の DrainNotifications を呼び出すことはできません。

ここに示すリターン コードの他に、Microsoft® .NET Alerts クライアント ライブラリのメソッドによって、標準の Win32 または COM の結果コードがシステムの下位層から返される場合があります。Microsoft Visual Studio® のエラー照合ツールを使用すると、これらの標準結果コードに関連付けられたヘルプ テキストを表示できます。

次の例は、DrainNotifications メソッドの使い方を示しています。

static void DemoDrainNotifications(
            NotificationTransportClass Transport)
{
    int Wait;
    int PendingCount;

    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.\n", PendingCount);

        // 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.\n");

        // 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}\n",
                        "The value of PendingCount (which should be 0) is: ",
                         PendingCount);

    } // End try.

    catch (COMException hr) // 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 catch.

} // End DemoDrainNotifications.