是否可以在Azure功能的Hub启动时运行代码?

gab*_*mgp 6 azure azure-functions

我希望在Azure Function的集线器启动时运行代码,并确保在该集线器中调用任何Azure功能之前执行该代码.我能这样做吗?

Mik*_*kov 7

鉴于您正在使用预编译的C#函数,您可以将初始化代码放入静态构造函数中:

public static class MyFunctionApp
{
    static MyFunctionApp()
    {
        // Runs once when class is first loaded
    }

    public void Run([SomeTrigger] input)
    {
        // Runs on each event
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 他们本身不必是同一个班级.他们只需要引用一个具有静态ctor的类.这只会起作用,您不必担心锁定.https://github.com/Azure/azure-webjobs-sdk-script/issues/586跟踪了更好的支持,但没有明确的ETA. (4认同)