Share via


NSInstance.ErrorEventHandler Delegate

NSInstanceError イベントを処理するメソッドを表します。

名前空間: Microsoft.SqlServer.NotificationServices
アセンブリ: Microsoft.SqlServer.NotificationServices (microsoft.sqlserver.notificationservices.dll 内)

構文

'宣言
Public Delegate Sub ErrorEventHandler ( _
    sender As Object, _
    e As ErrorEventArgs _
)
public delegate void ErrorEventHandler (
    Object sender,
    ErrorEventArgs e
)
public delegate void ErrorEventHandler (
    Object^ sender, 
    ErrorEventArgs^ e
)
/** @delegate */
public delegate void ErrorEventHandler (
    Object sender, 
    ErrorEventArgs e
)
JScript はデリゲートの使用をサポートしていますが、新規の宣言はサポートしていません。

パラメータ

  • sender
    エラーが発生した NSInstance オブジェクトです。
  • e
    イベント データを含む ErrorEventArgs オブジェクトです。

解説

Notification Services エンジンをホストする場合、このデリゲートを実装すると、Notification Services エンジンを実行しているスレッドを終了する致命的なエラーの発生が通知されます。処理できない致命的なエラーがエンジン スレッドによってスローされた場合、Notification Services はそのエラーをログに記録し、このデリゲートを呼び出します。

使用例

インスタンスの実行中に、ランタイム エラーが発生することがあります。これらのエラーは、Error イベントの発生時に呼び出された NSInstance.ErrorEventHandler デリゲートを通じてホスト側プロセスに報告されます。イベントが発生すると、デリゲートが呼び出されてイベントの発生をホストに通知し、インスタンスが停止されます。

このイベントに応答する例を次に示します。

// Define an error handler for the hosted execution engine.
private void InstanceErrorHandler(object sender, ErrorEventArgs e)
{
    Console.WriteLine (e.GetException ().ToString ());
}

// Start and stop the hosted execution engine.
public void ErrorHandlingStartStop()
{
    try
    {
        // Instantiate the Notification Services instance.
        NSInstance nsInstance = new NSInstance("FlightInstance");

        // Add an error handler to the instance.
        nsInstance.Error += 
            new NSInstance.ErrorEventHandler(InstanceErrorHandler);

        // Start the instance.
        Console.WriteLine("Starting instance...");
        nsInstance.StartInstance();

        // Check the IsRunning property to verify that 
        // this process is running the instance.
        if (nsInstance.IsRunning == true)
            Console.WriteLine("The instance is running.");
        else
            Console.WriteLine("The instance is NOT running!");


        // Stop the instance.
        Console.WriteLine("Stopping instance...");
        nsInstance.StopInstance();
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

プラットフォーム

開発プラットフォーム

サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。

対象プラットフォーム

サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。

参照

関連項目

Microsoft.SqlServer.NotificationServices Namespace