NSInstance.StartInstance Method
Starts the Notification Services engine for an instance of Notification Services.
Espace de noms: Microsoft.SqlServer.NotificationServices
Assembly: Microsoft.SqlServer.NotificationServices (in microsoft.sqlserver.notificationservices.dll)
Syntaxe
'Déclaration
Public Sub StartInstance
public void StartInstance ()
public:
virtual void StartInstance () sealed
public final void StartInstance ()
public final function StartInstance ()
Notes
On each computer that runs components of an instance of Notification Services, there is one Notification Services engine. This engine can be hosted by the NS$instanceNameMicrosoft Windows service, which can be created when you register an instance of Notification Services, or can be hosted by a custom application or service.
You can start and stop an instance of Notification Services on a computer using the StartInstance and StopInstance methods.
Important : |
---|
Only one process can run an instance of Notification Services on any computer. For example, if you create the NS$instanceName Windows service and start that service, and then attempt to start the instance in your own application, Notification Services will throw an error. |
For more information about hosting the engine, see Hébergement du moteur de Notification Services.
Exemple
The following examples show how to create, initialize, and start an NSInstance object in managed code:
' Define an error handler for the hosted execution engine.
Private Sub MyErrorHandler(ByVal sender As Object, _
ByVal e As ErrorEventArgs) Handles instance.Error
Console.WriteLine(e.GetException().ToString())
End Sub
' Start the instance, using the error handler to
' handle any exceptions thrown by the running instance.
Public Sub StartInstance(ByVal myInstance As NSInstance)
Try
'Start the instance.
myInstance.StartInstance()
' Verify that the hosted engine is running.
If myInstance.IsRunning = True Then
Console.WriteLine("The instance is running.")
Else
Console.WriteLine("The instance is NOT running!")
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
// Define an error handler for the hosted execution engine.
private void MyErrorHandler(object sender, ErrorEventArgs e)
{
Console.WriteLine(e.GetException().ToString());
}
// Start the instance, using the error handler to
// handle any exceptions thrown by the running instance.
public void StartInstance(NSInstance myInstance)
{
try
{
// Add an error handler to the instance.
myInstance.Error +=
new NSInstance.ErrorEventHandler(MyErrorHandler);
//Start the instance.
myInstance.StartInstance();
// Check the IsRunning property to verify that
// this process is running the instance.
if (myInstance.IsRunning == true)
Console.WriteLine("The instance is running.");
else
Console.WriteLine("The instance is NOT running!");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Sécurité des threads
Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Plateformes
Plateformes de développement
Pour obtenir la liste des plateformes prises en charge, consultez Configuration matérielle et logicielle requise pour l'installation de SQL Server 2005.
Plateformes cibles
Pour obtenir la liste des plateformes prises en charge, consultez Configuration matérielle et logicielle requise pour l'installation de SQL Server 2005.
Voir aussi
Référence
NSInstance Class
NSInstance Members
Microsoft.SqlServer.NotificationServices Namespace