Expand Minimize

ServiceCreatorCallback Delegate

Provides a callback mechanism that can create an instance of a service on demand.

Namespace:  System.ComponentModel.Design
Assembly:  System (in System.dll)

'Declaration
<ComVisibleAttribute(True)> _
<HostProtectionAttribute(SecurityAction.LinkDemand, SharedState := True)> _
Public Delegate Function ServiceCreatorCallback ( _
	container As IServiceContainer, _
	serviceType As Type _
) As Object

Parameters

container
Type: System.ComponentModel.Design.IServiceContainer

The service container that requested the creation of the service.

serviceType
Type: System.Type

The type of service to create.

Return Value

Type: System.Object
The service specified by serviceType, or Nothing if the service could not be created.

ServiceCreatorCallback provides a mechanism to publish services that you can request to have created when needed, rather than the service being created immediately when the designer loads. You can use a callback function if the service is not essential and may not be used. A service published by using a ServiceCreatorCallback does not use as many additional resources if it is not requested and created. To use a callback function to publish your service, pass a ServiceCreatorCallback to the AddService method of an IServiceContainer.

NoteNote

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: SharedState. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

The following code example shows how to publish a service using a callback function.

' The following code shows how to publish a service using a callback function. 

' Creates a service creator callback. 
Dim callback1 As New ServiceCreatorCallback _
(AddressOf myCallBackMethod)

' Adds the service using its type and the service creator.
serviceContainer.AddService(GetType(myService), callback1)

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft