I am developing a azure webjob which should run continuously. I have a public static function. I want this function to be automatically triggered without any queue. Right now i am using while(true) to run continuously. Is there any other way to do this?
Please find below my code
static void Main()
{
var host = new JobHost();
host.Call(typeof(Functions).GetMethod("ProcessMethod"));
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
[NoAutomaticTriggerAttribute]
public static void ProcessMethod(TextWriter log)
{
while (true)
{
try
{
log.WriteLine("There are {0} pending requests", pendings.Count);
}
catch (Exception ex)
{
log.WriteLine("Error occurred in processing pending altapay requests. Error : {0}", ex.Message);
}
Thread.Sleep(TimeSpan.FromMinutes(3));
}
}
Thanks
These steps will get you to what you want:
I converted your code to reflect the steps below.
static void Main()
{
var host = new JobHost();
host.CallAsync(typeof(Functions).GetMethod("ProcessMethod"));
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
[NoAutomaticTriggerAttribute]
public static async Task ProcessMethod(TextWriter log)
{
while (true)
{
try
{
log.WriteLine("There are {0} pending requests", pendings.Count);
}
catch (Exception ex)
{
log.WriteLine("Error occurred in processing pending altapay requests. Error : {0}", ex.Message);
}
await Task.Delay(TimeSpan.FromMinutes(3));
}
}