Closed jorgedevs closed 4 months ago
@jorgedevs can you paste the loop code here?
I assume it's this? await Task.Delay(TimeSpan.FromMinutes(1));
I'm curious to know if Thread.Sleep
works
And try it without a TimeSpan ... just pass an int for milliseconds
@adrianstevens excellent questions, thank you. I answered those questions updating the issue to give more context.
Since the test app above is incomplete, I created a new one (also attached). This code, running on 1.12.2, works fine.
public class MeadowApp : App<F7FeatherV2>
{
public override Task Run()
{
Resolver.Log.Info($"Device running {Device.Information.OSVersion}");
Task.Run(async () =>
{
while (true)
{
Resolver.Log.Info("TICK [Task.Delay FromMinutes]");
await Task.Delay(TimeSpan.FromMinutes(1));
}
});
Task.Run(async () =>
{
while (true)
{
Resolver.Log.Info("TICK [Task.Delay FromSeconds]");
await Task.Delay(TimeSpan.FromSeconds(60));
}
});
new Thread(() =>
{
while (true)
{
Resolver.Log.Info("TICK [Thread.Sleep FromSeconds]");
Thread.Sleep(TimeSpan.FromSeconds(60));
}
}).Start();
new Thread(() =>
{
while (true)
{
Resolver.Log.Info("TICK [Thread.Sleep FromMinutes]");
Thread.Sleep(TimeSpan.FromMinutes(1));
}
}).Start();
return base.Run();
}
}
Running with binaries v1.12.6.4
I have a my WiFiWeather Sample that has an infinite While loop, where in each cycle, i wait for one minute to either do an API call (to get Weather data) or just update the date time on my display.
I added a Console Output on each cycle, and I found out that the while loop iterates every 5 seconds approx and not every minute like I have coded in my app.
The loop looks like this:
Basically, I check im connected to my network, to iterate once every minute to update my Date and Time on my HMI screen, and every 10 minutes, I do a call to the web service to get my Weather data.
Things I've tried:
await Task.Delay(TimeSpan.FromMinutes(1));
withawait Task.Delay(60000);
, same resultThread.Sleep(60000);
and I still get the same result