Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
File association to registry fails?
grv575:
--- Quote from: Der Meister on January 04, 2006, 11:53:24 am ---
--- Quote from: killerbot on January 04, 2006, 11:45:07 am ---I can manually start several Firefox'es by clicking on the program icon of firefox. So it's not that only one instance can exist. Wonder how they do that ?
--- End quote ---
I don't know what firefox uses, but creating a named mutex is another common technique to allow only one running instance.
--- End quote ---
Yeah the common idiom is to use a named mutex and if it is already acquired then use IPC to pass over the commandline args to the existing instance and then exit.
killerbot:
that might be possible, yes, since you can query windows for the existing windows. And maybe they hand it over to the other one then.
[EDIT] It's like that, I checked the task manager, shortly there's an extra instance and then it is gone.
And if you have 2 firefoxes open, it will open it in the one that was last active.
So : options :
1) should we add such thing to CB also : query if others already runing and pass it over then (maybe even use selectable : start new instance (but then ths user should already have allowed multiple instance setting) or open in existing instance
2) Fix the DDE to get rid of the error messages
Drop the feedback ... ;-)
thomas:
--- Quote from: Der Meister on January 04, 2006, 11:53:24 am ---I don't know what firefox uses, but creating a named mutex is another common technique to allow only one running instance.
--- End quote ---
This is exactly what Code::Blocks does (wxSingleInstanceChecker does just that).
But: this does not solve the problem, it really makes it worse, it leads to the "another instance is already running, quitting now" issue.
The problem with multiple instances is that we need a bulletproof way to hand the commandline from a new instance to the already running instance. Unluckily, this is not precisely trivial to implement cross-platform.
A named pipe would do, but Linux pipes are not named. A message queue on Linux would do, too, but Windows has no such thing. TCP could be used, but that would make all those Windows application firewalls go frenzy. Gcc allows shared variables between processes, but that is compiler-specific and OS-specific in addition. A shared memory page could be used, but again, this is very OS-dependent. Tempfiles have been discussed, but were turned down due to race conditions...
It is not so simple really.
DDE is a fat, clumsy pig (like most MS technologies), but at least it works 90% of the time, except for the occasional "cannot find file" error. And since we are using the wxWidgets thingie for DDE, it should run on Unix, too (honestly, I don't know, but the docs claim that it does).
MortenMacFly:
--- Quote from: thomas on January 04, 2006, 12:34:02 pm ---The problem with multiple instances is that we need a bulletproof way to hand the commandline from a new instance to the already running instance.
--- End quote ---
I didn't expected this post to turn in such a big discussion, but I understand the problem by now. I would like to add the following: Some time ago I had a similar problem: Inform another instance of an application and be cross-platform (at least win/linux) compatible. I solved it by using the settings file. I put a flag "another_instance" and an address to post messages to into the settings file on startup. On application exit both are reset to zero. Thus another instance first checks the "another_instance" flag and sends a message to the address (shared memory in that case) if appropriate. Of course there are unresolved issues as well: If the application crashes the "another_instance" is not reset and things. Also, the main application was required to cyclic check the shared memory (which was OK for my purpose anyway). However: That time it was the "simplest" way I could think of and the application had only "tool-character"...
--- Quote from: thomas on January 04, 2006, 12:34:02 pm ---DDE is a fat, clumsy pig (like most MS technologies), [...]
--- End quote ---
Right, :lol: :lol: :lol:.
Morten.
thomas:
--- Quote ---I solved it by using the settings file. I put a flag "another_instance" and an address to post messages to into the settings file on startup.
--- End quote ---
This is almost certain to fail one day. It might appear to work for a while, but one day, it will fail. And the bad thing is when it happens, you will not know why, because you forgot about it a long time ago...
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version