Share via


IScheduledEventProvider.Run Method

Activates the event provider to begin collecting events.

Namespace: Microsoft.SqlServer.NotificationServices
Assembly: Microsoft.SqlServer.NotificationServices (in microsoft.sqlserver.notificationservices.dll)

Syntax

'Declaration
Function Run As Boolean
bool Run ()
bool Run ()
boolean Run ()
function Run () : boolean

Return Value

A Boolean value that indicates whether the event provider was able to run successfully.

Remarks

The provider host calls this method to start the event provider. The method must return true if the scheduled event provider has completed its current schedule interval and is prepared to exit. Otherwise, the method must return false. A false return value disables the event provider and prevents the event provider host from calling the Run method until the event provider is enabled.

When the notification application starts, the provider host calls the Initialize method on the scheduled event provider. The provider host reads the schedule information for this event provider, and then calls the event provider's Run method as indicated by the schedule in the application definition.

The provider host calls Run on every scheduled interval after the call to Initialize returns successfully. A scheduled event provider must return from the Run call within five minutes or before the next scheduled interval, whichever comes first. If you think your event collection routine will take longer than that to complete, you must program the event provider to either use a callback function, or to gather and submit events on one or more separate threads. If you choose to have multiple threads running in parallel and if event order is important to your application, make sure to synchronize the threads so that they submit events to the database in the same order in which they were created.

If the event provider has not returned when the next scheduled interval arrives, the provider host waits until the following interval to call Run again. To avoid missing calls, a scheduled event provider must always return from the Run method call on time. Make sure that you set the schedule of the event provider so that it can complete its tasks and return in a timely fashion.

A scheduled event provider will normally return false from the Run method to let the provider host know something is wrong and that it is not going to continue to run. If the scheduled event provider has already returned from Run and is now submitting events on a separate thread, then it must use the StopHandler delegate to notify the provider host that something has gone wrong. This delegate is passed to the event provider as an argument to the Initialize method, so that the event provider can invoke it if it needs to be terminated.

If exceptions are not handled, the provider host logs the unhandled error and then invokes the Initialize method on the event provider.

Example

For an example of how to implement the Run method, see the IScheduledEventProvider topic.

Thread Safety

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.

Platforms

Development Platforms

For a list of the supported platforms, see Hardware and Software Requirements for Installing SQL Server 2005.

Target Platforms

For a list of the supported platforms, see Hardware and Software Requirements for Installing SQL Server 2005.

See Also

Reference

IScheduledEventProvider Interface
IScheduledEventProvider Members
Microsoft.SqlServer.NotificationServices Namespace