Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ServiceCreatorCallback Delegate

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

[Visual Basic]
<Serializable>
<ComVisible(True)>
Public Delegate Function Sub ServiceCreatorCallback( _
   ByVal container As IServiceContainer, _
   ByVal serviceType As Type _
) As Object
[C#]
[Serializable]
[ComVisible(true)]
public delegate object ServiceCreatorCallback(
   IServiceContainer container,
   Type serviceType
);
[C++]
[Serializable]
[ComVisible(true)]
public __gc __delegate Object* ServiceCreatorCallback(
   IServiceContainer* container,
   Type* serviceType
);

[JScript] In JScript, you can use the delegates in the .NET Framework, but you cannot define your own.

Parameters [Visual Basic, C#, C++]

The declaration of your callback method must have the same parameters as the ServiceCreatorCallback delegate declaration.

container
The service container that requested the creation of the service.
serviceType
The type of service to create.

Remarks

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.

Example

[Visual Basic, C#, C++] The following code example shows how to publish a service using a callback function:

[Visual Basic] 
' 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)

[C#] 
// The following code shows how to publish a service using a callback function.

// Creates a service creator callback.
ServiceCreatorCallback callback1 = 
new ServiceCreatorCallback(myCallBackMethod);

// Adds the service using its type and the service creator callback.
serviceContainer.AddService(typeof(myService), callback1);

[C++] 
// The following code shows how to publish a service using a callback function.

// Creates a service creator callback.
ServiceCreatorCallback* callback1 = 
    new ServiceCreatorCallback(this, &Sample::myCallBackMethod);

// Adds the service using its type and the service creator callback.
serviceContainer->AddService(__typeof(myService), callback1);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel.Design

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

System.ComponentModel.Design Namespace | AddService | IServiceContainer

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft