Running multiple instances

Hhi,

 

I'm not sure that this is a Windows specific problem but I didn't know where else to post it, so sorry if it's the wrong place.

I just started to migrate my projects from Juce 1.53 to the current Juce version, which was quite a big step.

I managed it now so far, that I can start my applications again but I figured out, that I can't run multiple instances of my applications.

Neither two times the same application nor two different Juce applications although the moreThanOneInstanceAllowed( ) methods of both applications return true. They both start, but one is kind of blocked as long as the second one is running. As soon as I quit one the other one continues to run smoothly.

Juce 3 is pretty new to me so maybe I forgot some settings or something... 

I would really appreciate any help or hint because I'm getting a little bit stucked on that! Thanks in advance!

 

JUCEApplicationBase::moreThanOneInstanceAllowed ?

as i said, both JUCEApplicationBase::moreThanOneInstanceAllowed() methods return true...

Sorry, didn't notice you'd said that. Well, that's the only place where I've written any code that would stop multiple instances starting. Surely it's easy enough to debug it and see how far it gets?

I finally found the problem and will share my solution here in case somebody else has a similar problem:

 

Initial situation:

I have several applications based on Juce. One of it is a little logging window that all my other applications are using. For this purpose I'm using Juce's InterprocessCommunication class for creating several NamedPipes, where other processes can connect and write to. 

 

My problem was that each process is trying to connect via the InterprocessConnection::connectToPipe( ) method to the first pipe in the list and if the attemp fails it takes the next one and so on until it finds a free pipe. In Juce 1.53 this worked perfectly because the InterprocessConnection::connectToPipe( ) returned false in case another process is using the same pipe already. In the new Juce version, this function returned true although another process was already using the same pipe.

I traced the problem down to the NamedPipe::openInternal( ) method, which is always returning true in case the createPipe parameter is specified as false (which is the case for my client applications) without actually trying to connect to the pipe.

bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
{
    pimpl = new Pimpl (pipeName, createPipe);
    if (createPipe && pimpl->pipeH == INVALID_HANDLE_VALUE)
    {
        pimpl = nullptr;
        return false;
    }
    return true;
}

After changing this method to the following everything worked out fine:

bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
{
    pimpl = new Pimpl (pipeName, createPipe);
    if (createPipe)
    {
        if(pimpl->pipeH == INVALID_HANDLE_VALUE)
        {
            pimpl = nullptr;
            return false;
        }
        return true;
    }
    return pimpl->connect(100);
}

 

@Jules: is this a bug in the current Juce version or am I just using the NamedPipe class in a way I'm not supposed to? Is there a better way to implement my use case?

IIRC that might have been a problem in the old version that was fixed. I think the way it works is that it's ok to open a pipe without it connecting immediately, and it's only when you attempt to read or write that it'll succeed or fail.