Questa è la prima volta che eseguo un tipo di applicazione WebJob. Ho creato un progetto webjob e nella soluzione viene fornito con Program.cs
e Function.cs
.Azure WebJob Best Approach
Ho già rimosso Function.cs
perché in questo progetto non ci sarà alcuna coda da cui riceverò i dati.
Ora in Program.cs
c'è già Metodo principale come la seguente:
class Program
{
// Please set the following connection strings in app.config for this WebJob to run:
// AzureWebJobsDashboard and AzureWebJobsStorage
static void Main()
{
var host = new JobHost();
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
}
quanto ho capito, che RunAndBlock
è quello di eseguire il webjob continuamente, ma voglio eseguire il processo una sola volta. Voglio controllare l'esecuzione dall'esterno con un programma. Mi piacerebbe sapere come far funzionare il mio codice solo una volta? Come visto di seguito, ho una classe SupportService
che ha RunOnePoolProvisioingCycle
, voglio chiamare questo metodo una sola volta. È questo l'approccio giusto?
static void Main()
{
SupportService _supportService = new SupportService();
_supportService.Initialize();
_supportService.SetPoolProvisioningConfigurations();
_supportService.RunOnePoolProvisioningCycle();
}
o questo?
static void Main()
{
var host = new JobHost();
SupportService _supportService = new SupportService();
_supportService.Initialize();
_supportService.SetPoolProvisioningConfigurations();
host.Call(typeof(SupportService).GetMethod("SetPoolProvisioningConfigurations"));
}
o questo?
static void Main()
{
var host = new JobHost();
SupportService _supportService = new SupportService();
_supportService.Initialize();
_supportService.SetPoolProvisioningConfigurations();
host.CallAsync(typeof(SupportService).GetMethod("SetPoolProvisioningConfigurations"));
}
o devo usare:
host.Start()
o
host.StartAsync()?
Credo che tutte le risposte qui siano corrette, poiché la mia domanda riguarda l'approccio. ma devo sceglierne uno. questa nota per chiunque stia vedendo questo post. –