Clone controller

Hello guys,

I need to get component or function to make clone control function.
Better if this function will work with mutex. Fast and good.

Thanks,
Dan
DanDaemonAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Ferruccio AccalaiConnect With a Mentor Senior developer, analyst and customer assistance Commented:
Try this my component (with source) www.afsoftware.it\Downloads\AFJustOne.zip

F68 ;-)
0
 
DanDaemonAuthor Commented:
Hello F68,

Probably you have same which does not use function FindWindow?
I do not want to use this function :)

Thanks,
Dmitry
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
the findwindow is used just in MenuDependent mode....
You can remove that part if you don't need it or just check for a mutex created by the menu (if you need this feauture)...
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
DanDaemonAuthor Commented:
:) I so though... Thanks
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Glad to have helped you :)

F68 ;-)
0
 
Wim ten BrinkSelf-employed developerCommented:
What's a clone control function, exactly? :)

I happen to have an interesting unit at http://www.workshop-alex.org/Sources/untExtraInterfaces.pas that wraps an interface around mutexes, events, critical sections and semaphores that make them quite easy to use.

If you want to discover if a process is running, the mutex will work quite nicely. So is the Semaphore, which could limit your application to an X amount of processes running at the same time. But an alternative could be the use of an event...

Instead of a Mutex, you could use an event. Give it some unique name. In a special thread, you just wait for an infinite time until it is triggered. When the second application creates it, my IEvent interface wil set the Existing property to true, so you know it's a second call to the application. In that case, you set the event so the original application will be triggered to do something. Your second application could then close itself again.

Haven't tested it myself, though. But theoretically, it should work.
0
 
Wim ten BrinkSelf-employed developerCommented:
As a simple example:

program Bang;

{$APPTYPE CONSOLE}

uses
  Classes,
  untExtraInterfaces;

type
  TMyThread = class( TThread )
  private
    Event: IEvent;
  protected
    procedure Execute; override;
  public
    constructor Create;
    destructor Destroy; override;
  end;

constructor TMyThread.Create;
begin
  inherited Create( False );
  FreeOnTerminate := False;
  Event := NewEvent( False, False, 'UniqueName' );
  Resume;
end;

destructor TMyThread.Destroy;
begin
  Event := nil;
  inherited;
end;

procedure TMyThread.Execute;
var
  Count: Integer;
begin
  if Event.Existing then begin
    WriteLn( 'Application already running.' );
    Event.Signal;
  end
  else begin
    WriteLn( 'First-time run.' );
    Count := 5;
    repeat
      repeat until Event.Wait( 1000 );
      WriteLn( 'We got triggered. Counts left: ', Count );
      Dec( Count );
    until ( Count = 0 );
  end;
end;

begin
  TMyThread.Create.WaitFor;
  ReadLn;
end.
0
 
Wim ten BrinkSelf-employed developerCommented:
Darn. Already accepted? And I thought the method by events was much nicer. :)
0
All Courses

From novice to tech pro — start learning today.