ancora async/await

This commit is contained in:
Samuele E. Locatelli
2020-12-01 12:46:15 +01:00
parent 7a734975b9
commit da7c2e8136
+26 -25
View File
@@ -430,6 +430,7 @@ namespace IOB_MAN
}
finally
{
checkRunning = false;
if (hasLock)
{
Monitor.Exit(_locker);
@@ -743,6 +744,7 @@ namespace IOB_MAN
private void forceCheckTimer_Tick(object sender, EventArgs e)
{
#if false
if (!checkRunning)
{
try
@@ -755,6 +757,21 @@ namespace IOB_MAN
Logging.Instance.Error($"forceCheckTimer_Tick {exc}");
}
}
#endif
if (!checkRunning)
{
try
{
Task result = Task.Run(() => checkProcessStatusAsync().ConfigureAwait(false));
result.Wait();
}
catch (Exception exc)
{
Logging.Instance.Error($"forceCheckTimer_Tick {exc}");
}
}
checkWatchdog();
// riavvio i timer x sicurezza...
UI_Timer.Stop();
@@ -949,35 +966,19 @@ namespace IOB_MAN
/// <param name="e"></param>
private void MainTimer_Tick(object sender, EventArgs e)
{
var hasLock = false;
try
if (!checkRunning)
{
Monitor.TryEnter(_locker, ref hasLock);
if (!hasLock)
try
{
return;
//Task result = checkProcessStatusAsync();
//result.Wait();
Task result = Task.Run(() => checkProcessStatusAsync().ConfigureAwait(false));
result.Wait();
}
if (!checkRunning)
catch (Exception exc)
{
try
{
Task result = checkProcessStatusAsync();
result.Wait();
#if false
await Task.Run(() => checkProcessStatusAsync()).ConfigureAwait(false);
#endif
}
catch (Exception exc)
{
Logging.Instance.Error($"MainTimer_Tick {exc}");
}
}
}
finally
{
if (hasLock)
{
Monitor.Exit(_locker);
Logging.Instance.Error($"MainTimer_Tick {exc}");
}
}
}