本文整理汇总了C#中Microsoft.Azure.WebJobs.JobHost.StartAsync方法的典型用法代码示例。如果您正苦于以下问题:C# JobHost.StartAsync方法的具体用法?C# JobHost.StartAsync怎么用?C# JobHost.StartAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Azure.WebJobs.JobHost
的用法示例。
在下文中一共展示了JobHost.StartAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate_EndToEnd
public async Task Generate_EndToEnd()
{
// construct our TimerTrigger attribute ([TimerTrigger("00:00:02", RunOnStartup = true)])
Collection<ParameterDescriptor> parameters = new Collection<ParameterDescriptor>();
ParameterDescriptor parameter = new ParameterDescriptor("timerInfo", typeof(TimerInfo));
ConstructorInfo ctorInfo = typeof(TimerTriggerAttribute).GetConstructor(new Type[] { typeof(string) });
PropertyInfo runOnStartupProperty = typeof(TimerTriggerAttribute).GetProperty("RunOnStartup");
CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(
ctorInfo,
new object[] { "00:00:02" },
new PropertyInfo[] { runOnStartupProperty },
new object[] { true });
parameter.CustomAttributes.Add(attributeBuilder);
parameters.Add(parameter);
// create the FunctionDefinition
FunctionMetadata metadata = new FunctionMetadata();
TestInvoker invoker = new TestInvoker();
FunctionDescriptor function = new FunctionDescriptor("TimerFunction", invoker, metadata, parameters);
Collection<FunctionDescriptor> functions = new Collection<FunctionDescriptor>();
functions.Add(function);
// generate the Type
Type functionType = FunctionGenerator.Generate("TestScriptHost", "TestFunctions", functions);
// verify the generated function
MethodInfo method = functionType.GetMethod("TimerFunction");
ParameterInfo triggerParameter = method.GetParameters()[0];
TimerTriggerAttribute triggerAttribute = triggerParameter.GetCustomAttribute<TimerTriggerAttribute>();
Assert.NotNull(triggerAttribute);
// start the JobHost which will start running the timer function
JobHostConfiguration config = new JobHostConfiguration()
{
TypeLocator = new TypeLocator(functionType)
};
config.UseTimers();
JobHost host = new JobHost(config);
await host.StartAsync();
await Task.Delay(3000);
await host.StopAsync();
// verify our custom invoker was called
Assert.True(invoker.InvokeCount >= 2);
}