Skip to content

Commit aea2239

Browse files
author
Brian Macintosh
committed
Fixed an exception that occurred if the MainForm update loop was too slow
1 parent 029a53d commit aea2239

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

UnityProjectBrowser/MainForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private void UpdateLoop()
8383
UpdateAllObjectsList();
8484
}
8585
m_updateThreadSync.WaitOne();
86-
Thread.Sleep(UpdateInterval - stopwatch.Elapsed);
86+
Thread.Sleep(TimeSpanUtility.Max(TimeSpan.Zero, UpdateInterval - stopwatch.Elapsed));
8787
}
8888
}
8989

UnityProjectBrowser/UnityProjectBrowser.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<Compile Include="Structure\Unity\UnitySprite.cs" />
9797
<Compile Include="Structure\Unity\UnityFolder.cs" />
9898
<Compile Include="Utility\ListViewExtender.cs" />
99+
<Compile Include="Utility\TimeSpanUtility.cs" />
99100
<Compile Include="Utility\UnityClassIds.cs" />
100101
<EmbeddedResource Include="GotoForm.resx">
101102
<DependentUpon>GotoForm.cs</DependentUpon>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright(c) 2018 Brian MacIntosh
2+
// MIT License
3+
4+
using System;
5+
6+
namespace UnityProjectBrowser
7+
{
8+
public static class TimeSpanUtility
9+
{
10+
/// <summary>
11+
/// Returns the greater of the two <see cref="TimeSpan"/>s.
12+
/// </summary>
13+
public static TimeSpan Max(TimeSpan a, TimeSpan b)
14+
{
15+
return a > b ? a : b;
16+
}
17+
18+
/// <summary>
19+
/// Returns the lesser of the two <see cref="TimeSpan"/>s.
20+
/// </summary>
21+
public static TimeSpan Min(TimeSpan a, TimeSpan b)
22+
{
23+
return a > b ? b : a;
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)