简体   繁体   English

我可以在代码中运行Azure函数吗?

[英]Can i run Azure Functions in code?

Can i run Azure Functions in code? 我可以在代码中运行Azure函数吗?

I mean, that having some c# project and host it on Azure i want to user Timer to do background work time by time. 我的意思是,拥有一些c#项目并将其托管在Azure上,我希望用户Timer可以逐时进行后台工作。 Have Azure SDK (or so on) some methods to implements timer line Azure Functions but in code? 是否有Azure SDK(或诸如此类)某些方法可在代码中实现计时器行Azure Functions

PS i mean than can i use somelike Azure Function methods in App Service? PS:我的意思是我可以在App Service中使用类似的Azure Function方法吗? For example, i want to run some piece of code every 5 minute, but not all code. 例如,我想每5分钟运行一段代码,但不是全部代码。

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). 其中AzureFunctionTimer是Azure SDK的一部分(例如)。

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. 我认为(也许是我错了),即使使用的时间尚未增加,使用诸如System.Threading.Timer计时器也会在Azure主机上使用CPU计时器。

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). 为了防止出现这种情况,应使用某些Azure SDK函数,例如Azure Function (如果存在)。

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. 我不太确定您要问的是什么,但是如果您尝试使用Azure Functions每5分钟(或任何时间段)运行某项内容,则可以使用计时器功能。 This means that the function will automatically trigger every 5 minutes and run your code. 这意味着该函数将每5分钟自动触发一次并运行您的代码。 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仪表板创建新功能时,其中一个模板用于“计时器”,它使您可以在定义的每个期间运行一些代码。

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

Azure Functions works in a reactive way, it will only run when an event happen. Azure Functions以反应性方式工作,仅在事件发生时才运行。 So the best you can do is use a kind of trigger (http Trigger for example) and call your Azure Function when you need. 因此,最好的办法是使用一种触发器(例如,http触发器),并在需要时调用Azure函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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