只允许程序运行一个实例.如果已运行.并调用此实例中的某公共方法??

解决方案 »

  1.   

    codeproject 上有相关解决方法
      

  2.   

    设计模式中的Singleton模式
    public class Test
    {
       private Test(){}
       public static readonly Test test = new Test();
       public void Method(){...}
       ...
    }public class App
    {
       Test.test.Method();
    }
    这样就满足了始终只能调用一个实例.
      

  3.   

    to:linuxdotnet(linuxdotnet)
    能给出具体链接吗???
    我程序通过某文件右键菜单启动.程序中将会显示此文件路径.
    我得在主界面中刷新并显示此路径呀!用静态方法这实现不了呀!
      

  4.   

    用mutex确保程序只有一个实例运行
      

  5.   

    MUTEX这我能做到.因为相关资料中已给出答案了.但是如果此实例运行了.那么我要得到此实例对像.然后用此对像调用它的某一公共方法!这才是问题的关健!
      

  6.   

    上边的singleton不是给出了吗?class App
    {
    private static App  onlyOne;
            public App getApp()
            {
                  if(onlyOne==null) onlyOne=new App();
                  retrun onlyOne;
            }
            protected App()
            {}
            public void method()
             
            {
            //////////do something
            }
    }