Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit c1f332d

Browse files
committed
Add try/catch for setting the process priority class, ignoring the exception if its message is "Success".
1 parent 636aff0 commit c1f332d

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/GitTools.Core/GitTools.Core.Shared/Helpers/ProcessHelper.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public static Process Start(ProcessStartInfo startInfo)
2424
try
2525
{
2626
process = Process.Start(startInfo);
27-
process.PriorityClass = ProcessPriorityClass.Idle;
2827
}
2928
catch (Win32Exception exception)
3029
{
31-
// NOTE: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 @asbjornu
30+
// NOTE: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382.aspx
31+
// -- @asbjornu
3232
if (exception.NativeErrorCode == 2)
3333
{
3434
throw new FileNotFoundException(string.Format("The executable file '{0}' could not be found.",
@@ -39,6 +39,28 @@ public static Process Start(ProcessStartInfo startInfo)
3939

4040
throw;
4141
}
42+
43+
try
44+
{
45+
if (process != null)
46+
{
47+
process.PriorityClass = ProcessPriorityClass.Idle;
48+
}
49+
}
50+
catch (Win32Exception exception)
51+
{
52+
53+
// NOTE: It seems like in some situations, setting the priority class will throw an exception
54+
// with the error code set to "Success", which I think we can safely interpret as a success and
55+
// not an exception.
56+
// See https://travis-ci.org/GitTools/GitVersion/jobs/171288284#L2026
57+
// and https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382.aspx
58+
// -- @asbjornu
59+
if (exception.NativeErrorCode == 0)
60+
{
61+
throw;
62+
}
63+
}
4264
}
4365
}
4466

@@ -137,7 +159,7 @@ public struct ChangeErrorMode : IDisposable
137159
public ChangeErrorMode(ErrorModes mode)
138160
{
139161
try
140-
{
162+
{
141163
oldMode = SetErrorMode((int)mode);
142164
}
143165
catch (EntryPointNotFoundException)
@@ -150,7 +172,7 @@ public ChangeErrorMode(ErrorModes mode)
150172
void IDisposable.Dispose()
151173
{
152174
try
153-
{
175+
{
154176
SetErrorMode(oldMode);
155177
}
156178
catch (EntryPointNotFoundException)

0 commit comments

Comments
 (0)