AppMetrics.AgentService.AgentServiceClass.TerminatePlugin C# (CSharp) Method

TerminatePlugin() private method

private TerminatePlugin ( PluginInfo plugin ) : void
plugin PluginInfo
return void
        private void TerminatePlugin(PluginInfo plugin)
        {
            lock (_pluginsSync)
            {
                var exePath = Const.GetPluginExePath(plugin.Name);
                if (plugin.Process == null)
                {
                    // stop any processes left from the previous agent launch, if any. normally this should not happen
                    var processName = Path.GetFileNameWithoutExtension(exePath);
                    var processes = Process.GetProcessesByName(processName);
                    foreach (var process in processes)
                    {
                        KillProcess(process);
                    }
                }
                else
                {
                    KillProcess(plugin.Process);
                    plugin.Process = null;
                }
            }
        }