我想做一个程序 其功能是限制指定的程序同时运行  也就是说 我想要一个程序只给同时运行三个 多于三多的禁止在运行请高手们给点思路 谢谢!!

解决方案 »

  1.   


    建立二个互斥, CreateMutex('APP1')
     CreateMutex('APP2') 如果二个都存在了就不允许了。::)
      

  2.   

    居然忘了互斥对象……Starluck的办法比我的简便一些,建议用他的办法
      

  3.   

    a
    b
    c 三條路,E這個人來走,A占用,B也占用,只能走C,如果C也占用了,就沒路了建二個互斥就行了。還不明白?
      

  4.   

    我用了三个互斥才实现的,不知道如何建两个就行了
    program LiveAuction;{$APPTYPE CONSOLE}uses
      SysUtils,
      Windows,
      Forms,
      ShellAPI;var
      a,b,c:string;
      H:HWND;
    begin
      { TODO -oUser -cConsole Main : Insert code here }
      Application.Initialize;
      a:='first';
      b:='second';
      c:='third';
      Application.Title:='LiveAuction';  H:=OpenMutex(MUTEX_ALL_ACCESS,False,PChar(a));
      if H<>0 then
        begin
         H:=OpenMutex(MUTEX_ALL_ACCESS,False,PChar(b));
         if H<>0 then
            begin
               H:=OpenMutex(MUTEX_ALL_ACCESS,False,PChar(c));
               if H<>0 then
                  begin
                      Exit;
                  end
                  else
                     CreateMutex(nil,False,PChar(c));
            end
            else
            CreateMutex(nil,False,PChar(b));
        end
        else
        CreateMutex(nil,False,PChar(a));  Application.Run;
      write('good!');
      Readln;
    end.参考资料:
    http://www.cnblogs.com/taobataoma/archive/2007/08/15/856415.html
    http://baike.baidu.com/view/2422945.htm
    www.cnitlaw.cn
      

  5.   

    向starluck 提问,怎么用两个互斥就可以实现啊???我都快晕了!
      

  6.   

    用Semaphore不就完了,建那么多Mutex干嘛,还麻烦