An initializer function is used to ensure that functions are executed on the same instance only once. This topic describes the basic structure and features of C# initializer functions.

Definition

Function Compute provides the Init method to initialize instances. The Init method is automatically called when an instance starts in the background. The Init method is called only once for each instance.

The following code defines the Init method of a simple initializer function. For more information about initializer functions, see Initializer function.

public void Init(); //No context object is contained.
public void Init(IFcContext context); //The context object is contained.
public static void Init(); //No context object is contained.
public static void Init(IFcContext context); //The context object is contained.

Function name

The function name MyInitializer must correspond to the initializer field that you specify when you create an initializer function. For example, if you set the initializer handler field to fcdotnetsample::fcdotnetsample.TestHandler::MyInitializer when you create an initializer function, the MyInitializer function that is defined in the fcdotnetsample.TestHandler file is regarded as the initializer function. After the configuration is complete, Function Compute loads the MyInitializer function as the initializer function.

Features

  • The FunctionInitializer and InitializationTimeout fields that are contained in FunctionParam of IFcContext are designed for initializer functions. If these two fields are not specified, the initializer function is not executed.
  • Initializer functions return no values. Return logic that is appended to initializer functions does not take effect.