static void Main(string[] args) { bool isFound = false; foreach (Process PPath in Process.GetProcessesByName("node")) { int processId = PPath.Id; string processArgs = ""; var q = string.Format("select CommandLine from Win32_Process where ProcessId='{0}'", processId); ManagementObjectSearcher searcher = new ManagementObjectSearcher(q); ManagementObjectCollection result = searcher.Get(); foreach (ManagementObject obj in result) { processArgs = obj["CommandLine"].ToString(); if (processArgs.ToLower().Contains("appium")) { isFound = true; PPath.Kill(); Console.WriteLine("Killed process id {0} : {1}", processId, processArgs); } } } if (!isFound) { Console.WriteLine("No process found for appium"); } }
static void Main() { foreach (Process PPath in Process.GetProcesses()) { if (PPath.ProcessName == Process.GetCurrentProcess().ProcessName) { if (PPath.Id == Process.GetCurrentProcess().Id) { continue; } DialogResult dialogResult = MessageBox.Show("Chương trình đã đang chạy, nhấn OK để tắt chương trình và mỏ phiên làm việc mới", "Cảnh báo", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { PPath.Kill(); } else if (dialogResult == DialogResult.No) { return; } } } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); System.Threading.ThreadPool.SetMinThreads(100, 100); // UI thread Exceptions Application.ThreadException += Application_ThreadException; Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); // Make this for boosting RestSharp performance. System.Net.ServicePointManager.UseNagleAlgorithm = false; //Application.Run(new fPower1()); fLoginForm loginForm = new fLoginForm(); if (loginForm.ShowDialog() == DialogResult.OK) { //Z119.ATK.Common.Const.projMan.LoadProject(); //projMan.SelectedProject += frm_SelectedProject; Z119.ATK.Common.Const.projMan.LoadProject(); Application.Run(Z119.ATK.Common.ProjectManager.LoadObject <fMainWindow>(Z119.ATK.Common.Const.FILE_MAINWINDOW)); } //else // Application.Exit(); }
public static void Main(string[] args) { var currentPId = Process.GetCurrentProcess().Id; foreach (Process PPath in Process.GetProcesses()) { if (PPath.ProcessName.StartsWith("Web.App") && PPath.Id != currentPId) { PPath.Kill(); } } var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var serviceProvider = scope.ServiceProvider; try { var userManager = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >(); var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >(); var context = serviceProvider.GetRequiredService <CustomConnectionContext>(); var configuration = serviceProvider.GetRequiredService <IConfiguration>(); DbInitializer.StaticInitialize(context, userManager, roleManager, configuration); } catch { } } #if !DEBUG OpenBrowser("http://localhost:5001/"); #endif host.Run(); }