Solved

Clone controller

Posted on 2004-09-06
8
210 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:DanDaemon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 70 total points
ID: 11989685
Try this my component (with source) www.afsoftware.it\Downloads\AFJustOne.zip

F68 ;-)
0
 

Author Comment

by:DanDaemon
ID: 11989897
Hello F68,

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

Thanks,
Dmitry
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 11989918
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:DanDaemon
ID: 11989957
:) I so though... Thanks
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 11989968
Glad to have helped you :)

F68 ;-)
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11990069
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
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11990147
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
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11990153
Darn. Already accepted? And I thought the method by events was much nicer. :)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question