Extending - Threads
Managed Thread
public static ThreadRegistry AddCustomXYZFunction(this ThreadRegistry tr)
{
//Create a regular managed thread (not an expression, CRON)
var TM = new ManagedThread("CustomXYZFunction", (ct, l) => {
//The callback method is here...
do
{
//An example of repeating something every second, and exiting the thread when the token is cancelled.
//Doing a long process that can be stopped safely? Pay attention to the cancellation token, and kindly exit when a graceful shutdown is requested.
if (ct.IsCancellationRequested)
{
//Save or finish or persist information.
return;
}
}
while (PerigeeApplication.delayOrCancel(1000, ct));
}, tr.CTS, tr.GetLogger<Program>(), started: true);
//Set additional options
TM.ExceptionRestartTime = TimeSpan.FromSeconds(30);
//Add the thread to the management system
tr.AddManagedThread(TM);
return tr;
}Expression Thread
Last updated

