zoukankan      html  css  js  c++  java
  • 杀线程的代码(转自CSDNcyfboy)

    private void KillProcess(string processName)
            
    {
                System.Diagnostics.Process myproc 
    = new System.Diagnostics.Process();
                
    //得到所有打开的进程
                try
                
    {
                    
    foreach (Process thisproc in Process.GetProcessesByName(processName))
                    
    {
                        
    if (!thisproc.CloseMainWindow())
                        
    {
                            thisproc.Kill();
                        }
                        
                    }

                }

                
    catch (Exception Exc)
                
    {
                    MessageBox.Show(Exc.ToString());
                }

            }


            
    private void Form1_Load(object sender, EventArgs e)
            
    {
                String tempName 
    = "";
                
    int begpos;
                
    int endpos;

                
    foreach (Process thisProc in System.Diagnostics.Process.GetProcesses())
                
    {
                    tempName 
    = thisProc.ToString();
                    begpos 
    = tempName.IndexOf("("+ 1;
                    endpos 
    = tempName.IndexOf(")");
                    tempName 
    = tempName.Substring(begpos, endpos - begpos);
                    
    //this.listBox1.Items.Add(tempName);
                    if (tempName == "newfax")
                    
    {
                        KillProcess(tempName);
                    }

                }

            }


  • 相关阅读:
    OAuth2.0标准类库汇总
    RabbitMQ:Docker环境下搭建rabbitmq集群
    WCF&AppFabric :异常消息: 内存入口检查失败
    前端框架Vue、Angular、React
    串口驱动开发
    组合而不是继承,单一职责
    项目管理的一个月
    软件架构的一个设想以及谈一下过去两年开发软件的过失
    TCP中需要了解的东西
    C++编程新思维中的技巧
  • 原文地址:https://www.cnblogs.com/Magicsky/p/525312.html
Copyright © 2011-2022 走看看