I have Windows service that needs to monitor different things in the system (connect to some WCF services, send some data, etc.) every minute.
For that I chose to use Quartz.NET jobs which look as follows:
internal class MonitorLaunchJob : IJob
{
public void Execute(IJobExecutionContext context)
{
MonitorBase[] monitors = GetAllMonitors();
foreach (var monitor in monitors)
var task = monitor.Launch();
}
}
monitor.Launch
is the method with the following signature:
public abstract Task Launch()
The overrides of this method may use long-running operations like await TcpClient.ConnectAsync()
and stuff like that. Those methods track their activity by themselves using a lot of logging, so I don't need to keep track of the Task
returned by monitor.Start()
. I need to just fire and forget.
Now, my question is: what do I do with this task
that Launch
method returns? I can't think of a reason to store it anywhere since it's a fire-and-forget operation. But on the other hand, if a method returns an object, it is weird to just ignore it. Do I need to do any sort of clean-up when the task
is completed? Will I face any performance issues if I just leave the task be and never track its state?