简体   繁体   中英

Can i run Azure Functions in code?

Can i run Azure Functions in code?

I mean, that having some c# project and host it on Azure i want to user Timer to do background work time by time. Have Azure SDK (or so on) some methods to implements timer line Azure Functions but in code?

PS i mean than can i use somelike Azure Function methods in App Service? For example, i want to run some piece of code every 5 minute, but not all code.

Hm.. thank you for your answers! What i mean:

 var azureTimer=new AzureFunctionTimer(5*60*1000);
 azureTimer.Elapsed+=SomeHandler;

Where AzureFunctionTimer is a part of Azure SDK (for example).

Why am i ask? I think (and may be i am wrong) that using a some timer like System.Threading.Timer utilize CPU timer at Azure host even event of elapsed time not rising yet.

For example:

  var timer=new Timer(5*60*1000);
      timer.Elapsed+=SomeHandler; 
      timer.Start(); //and while timer not rise event it utilize CPU already. (Am i right?)

And to prevent it should use some Azure SDK function like Azure Function (if it exist).

I'm not quite sure what you're asking, but if you're trying to use Azure Functions to run something every 5 minutes (or whatever period), you can make a timer function. This means that the function will automatically trigger every 5 minutes and run your code. When you use the Azure Dashboard to create a new function, one of the templates is for "Timer" which will let you run some code every period you define.

不可以,您不能使用计时器,Azure Functions将在5分钟后关闭,但是您可以在计时器上外部调用它们(webhooks),或使用内部Azure Functions cron计划或其他事件,例如队列中的新消息。

Azure Functions works in a reactive way, it will only run when an event happen. So the best you can do is use a kind of trigger (http Trigger for example) and call your Azure Function when you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM