Skip to content

Commit 9f049ae

Browse files
committed
Vario: move to async
1 parent 5357b42 commit 9f049ae

File tree

2 files changed

+66
-64
lines changed

2 files changed

+66
-64
lines changed

ExtLibs/Utilities/Vario.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using System.Threading.Tasks;
56

67
namespace MissionPlanner.Utilities
78
{
@@ -21,10 +22,8 @@ public static void SetValue(float climbrate)
2122
Vario.climbrate = climbrate;
2223
}
2324

24-
public static void mainloop(object o)
25+
public static async void mainloop(object o)
2526
{
26-
System.Threading.Thread.CurrentThread.IsBackground = true;
27-
2827
while (run)
2928
{
3029
float note = climbrate *30 + MidTone;
@@ -38,7 +37,7 @@ public static void mainloop(object o)
3837
if (climbrate > 0)
3938
{
4039
Console.Beep((int)note, 300 - (int)(climbrate * 5));
41-
System.Threading.Thread.Sleep(20);
40+
await Task.Delay(20).ConfigureAwait(false);
4241
}
4342
else
4443
{
@@ -48,7 +47,7 @@ public static void mainloop(object o)
4847
else
4948
{
5049
// sleep when there is no sound required
51-
System.Threading.Thread.Sleep(100);
50+
await Task.Delay(100).ConfigureAwait(false);
5251
}
5352

5453
}
@@ -60,7 +59,10 @@ public static void mainloop(object o)
6059
public static void Start()
6160
{
6261
run = true;
63-
System.Threading.ThreadPool.QueueUserWorkItem(mainloop);
62+
Task.Run(() =>
63+
{
64+
mainloop(null);
65+
});
6466
}
6567

6668
public static void Stop()
Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Reflection;
5-
using System.Text;
6-
using System.Text.RegularExpressions;
7-
using log4net;
8-
9-
namespace MissionPlanner.Utilities
10-
{
11-
public class VersionDetection
12-
{
13-
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
14-
15-
public static Version GetVersion(string input)
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Text;
6+
using System.Text.RegularExpressions;
7+
using log4net;
8+
9+
namespace MissionPlanner.Utilities
10+
{
11+
public class VersionDetection
12+
{
13+
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
14+
15+
public static Version GetVersion(string input)
1616
{
17-
Regex versionregex = new Regex(@"([0-9]+)\.([0-9]+)(\.([0-9]+)|-rc([0-9]+)|([a-z]{2,20})|([a-z]))*");
18-
19-
// string ans = mat1.Groups[1].Value.ToString() + mat1.Groups[2].Value.ToString() + mat1.Groups[4].Value.ToString() + mat1.Groups[5].Value.ToString() + mat1.Groups[6].Value.ToString();
20-
21-
var match = versionregex.Match(input);
22-
23-
log.Info(input);
24-
25-
if (match.Success)
26-
{
27-
// start with major.monor
28-
string verstring = match.Groups[1].Value.ToString() + "." + match.Groups[2].Value.ToString();
29-
30-
if (!String.IsNullOrEmpty(match.Groups[4].Value))
31-
{
32-
verstring += "." + match.Groups[4].Value.ToString();
33-
}
34-
if (!String.IsNullOrEmpty(match.Groups[5].Value))
35-
{
36-
// -rc
37-
verstring += "." + match.Groups[5].Value.ToString();
38-
}
39-
if (!String.IsNullOrEmpty(match.Groups[6].Value))
40-
{
41-
// dev
42-
verstring += ".255";
43-
}
44-
if (!String.IsNullOrEmpty(match.Groups[7].Value))
45-
{
46-
// convert a to 1, b to 2, etc, it will break at j
47-
verstring += "." + (char) ((match.Groups[6].Value.ToString().ToLower()[0]) - 0x30);
48-
}
49-
50-
Version version = new Version(verstring);
51-
52-
log.Info(version.ToString());
53-
54-
return version;
55-
}
56-
57-
throw new Exception("Bad Version");
58-
}
59-
}
17+
Regex versionregex = new Regex(@"([0-9]+)\.([0-9]+)(\.([0-9]+)|-rc([0-9]+)|([a-z]{2,20})|([a-z]))*");
18+
19+
// string ans = mat1.Groups[1].Value.ToString() + mat1.Groups[2].Value.ToString() + mat1.Groups[4].Value.ToString() + mat1.Groups[5].Value.ToString() + mat1.Groups[6].Value.ToString();
20+
21+
var match = versionregex.Match(input);
22+
23+
log.Info(input);
24+
25+
if (match.Success)
26+
{
27+
// start with major.monor
28+
string verstring = match.Groups[1].Value.ToString() + "." + match.Groups[2].Value.ToString();
29+
30+
if (!String.IsNullOrEmpty(match.Groups[4].Value))
31+
{
32+
verstring += "." + match.Groups[4].Value.ToString();
33+
}
34+
if (!String.IsNullOrEmpty(match.Groups[5].Value))
35+
{
36+
// -rc
37+
verstring += "." + match.Groups[5].Value.ToString();
38+
}
39+
if (!String.IsNullOrEmpty(match.Groups[6].Value))
40+
{
41+
// dev
42+
verstring += ".255";
43+
}
44+
if (!String.IsNullOrEmpty(match.Groups[7].Value))
45+
{
46+
// convert a to 1, b to 2, etc, it will break at j
47+
verstring += "." + (char) ((match.Groups[6].Value.ToString().ToLower()[0]) - 0x30);
48+
}
49+
50+
Version version = new Version(verstring);
51+
52+
log.Info(version.ToString());
53+
54+
return version;
55+
}
56+
57+
throw new Exception("Bad Version");
58+
}
59+
}
6060
}

0 commit comments

Comments
 (0)