Skip to content

Commit 1de1b31

Browse files
JinhuafeiHongGit
authored andcommitted
adding null check in KillProcess task (#54)
1 parent fbd1ca3 commit 1de1b31

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/Packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/build/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,27 @@
6262
using(var results = searcher.Get())
6363
{
6464
var mo = results.Cast<ManagementObject>().FirstOrDefault();
65-
Log.LogMessage("ExecutablePath is {0}", (string)mo["ExecutablePath"]);
66-
if(mo != null && ((string)mo["ExecutablePath"]).StartsWith(ImagePath, StringComparison.OrdinalIgnoreCase))
65+
if(mo != null)
6766
{
68-
p.Kill();
69-
p.WaitForExit();
70-
Log.LogMessage("{0} is killed", (string)mo["ExecutablePath"]);
71-
break;
67+
var path = (string)mo["ExecutablePath"];
68+
var executablePath = path != null ? path : string.Empty;
69+
Log.LogMessage("ExecutablePath is {0}", executablePath);
70+
71+
if(executablePath.StartsWith(ImagePath, StringComparison.OrdinalIgnoreCase))
72+
{
73+
p.Kill();
74+
p.WaitForExit();
75+
Log.LogMessage("{0} is killed", executablePath);
76+
break;
77+
}
7278
}
7379
}
7480
}
7581
}
7682
}
7783
catch (Exception ex)
7884
{
79-
Log.LogErrorFromException(ex);
85+
Log.LogWarning(ex.Message);
8086
}
8187
return true;
8288
]]>

0 commit comments

Comments
 (0)