C#判断程序是否运行

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;
using System.Collections;

namespace DataUpper
{
    
static class Program
    
{
        
/// <summary>
        
/// 应用程序的主入口点。
        
/// </summary>

        [STAThread]
        
static void Main()
        
{
            
int iProcessNum = 0;

            
foreach (Process singleProc in Process.GetProcesses())
            
{
                
if (singleProc.ProcessName == Process.GetCurrentProcess().ProcessName)
                
{
                    iProcessNum 
+= 1;
                }

            }


            
if (iProcessNum > 1)
            
{
                MessageBox.Show(
"该程序已经在运行中!""天科多协议处理子程序", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            
else
            
{
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(
false);
                Application.Run(
new DataUpper());
            }

        }

    }

}
posted on 2008-12-01 18:18  一路前行  阅读(2403)  评论(0编辑  收藏  举报