设个static变量,如  hadrun = false
程序运行之初用
  if (hadrun)
      ...//已运行了
  else
     {
      hadrun = true ;//开始运行一个实例
      ...程序主要内容
      }
以上代码理论上是可以的。 

解决方案 »

  1.   

    ^_^,楼主能详细一点说明你想干什么,
    想帮助ing^_^
      

  2.   

    我用一个程序启运JAVA程序来完成一个任务,但我下在在重新启动时如果上一个还没有完成则新程序自动退出,就是系统级的的信号灯或事件对像吧。
    以下是VC的代码,我想实现类似功能。
    BOOL CReportApp::InitInstance()
    {
    HANDLE hEvent=CreateEvent(NULL,TRUE,0,"CZBG_MQRK");
    if(GetLastError()==ERROR_ALREADY_EXISTS)
    {
    Log("ÓÐһͬÀý³ÌÔÚÔËÐС£");
    return FALSE;
    }
             ......
    }
      

  3.   

    public class StaticTest {
        private static StaticTest test;
        private StaticTest() {
        }
        public static StaticTest getIntance(){
            return test = new StaticTest();
        }
    }
      

  4.   

    使用singleton模式
    public class SingleInstance {
    private static SingleInstance instance;
    private SingleInstance(){
    //........
    }
    public static SingleInstance getInstance(){
    //.....
    if (instance == null) {
    instance = new SingleInstance();
    }
    return instance;
    }
    }