Starting of Azure WebJob

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

Assuming that there is a function set inside of the WebJob shown on picture below,

image

there are several options to start this job from your executable file.

If you want to start the manually triggered webjob function, use following code:

JobHost host = new JobHost();

Task callTask = host.CallAsync(typeof(Functions).GetMethod("ManualTrigger"));

callTask.Wait();

This code will run the function and wait on completion. It he function is running in a endless loop (game-loop), it is called continuous job and it will run until process is terminated.

If you want to run a manually triggered action (or continuous job), but also to activate other automatically triggered functions use following code:

  JobHost host = new JobHost();
 
Task callTask = host.CallAsync(typeof(Functions).GetMethod("ManualTrigger"
));
 
Console.WriteLine("Waiting for async operation..."
);
  callTask.Wait();

  Console.WriteLine("Task completed: " + callTask.Status);
  host.RunAndBlock();

This code will first run manually triggered function and wait on completion. If the function is continuous job, it will never complete and automatically triggered functions will never be called. In that case remove callTask.Wait().
After completion (or start) of manually triggered function we will run the host with RunAndBlock(). This call will initialize all automatically triggered functions.

If you don’t have any manually triggered function use following code:

JobHost host = new JobHost();
host.RunAndBlock();


Posted Jun 07 2016, 09:59 AM by Damir Dobric
developers.de is a .Net Community Blog powered by daenet GmbH.