Cinchoo – Allow multi-instance application

Multi-Instance Application

Cinchoo is an application framework for .NET. One of the main functionality it provides to users is application configuration management. It also offers few other key functionalities like Common ApplicationHost, BCL etc.

When you choose to use this library in your application, it will inherently allow only one instance of your application running at any time. This is the default behavior. When you run the second instance, it will throw below application error and followed by application termination.

Already another instance of this application running.

This behavior can be override able to allow more than one instance of your application can be runnable at any time. There are couple of ways you can do so.

Programmatically

This section illustrates on how to allow multiple instances of your application run at the same time. Simply subscribe to ChoApplication.ApplyGlobalApplicationSettingsOverrides event as below

class Program
{
    static void Main(string[] args)
    {
        ChoApplication.ApplyGlobalApplicationSettingsOverrides += new EventHandler<ChoEventArgs<ChoGlobalApplicationSettings>>(ChoApplication_ApplyGlobalApplicationSettingsOverrides);

        ChoConsole.PauseLine();
    }

    static void ChoApplication_ApplyGlobalApplicationSettingsOverrides(object sender, ChoEventArgs<ChoGlobalApplicationSettings> e)
    {
        e.Value.ApplicationBehaviourSettings.SingleInstanceApp = false;
    }
}

PS: Make sure these initializations happens at the application entry point. In Windows Service, the event subscriptions are done at OnStart() method in ServiceBase subclass. In ASP.NET, the subscriptions are done in Application_Start() in Global.aspx file.

Configuration

This section illustrates how to make this through via configuration. Open the ChoCodeFrx.xml file. Look for singleInstanceApp attribute and assign ‘false’ as value. See sample below

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <globalApplicationSettings applicationId="ConfigFileOverride.Test.exe" eventLogSourceName="ConfigFileOverride.Test.exe">
    <behaviourSettings hideWindow="false" bringWindowToTop="false" alwaysOnTop="false" runAtStartup="false" runOnceAtStartup="false" singleInstanceApp="true" activateFirstInstance="false" showEnvironmentSelectionWnd="true" />
    ...
  </globalApplicationSettings>
  <metaDataFilePathSettings>
    ...
  </metaDataFilePathSettings>
</configuration>

 

Advertisements

1 thought on “Cinchoo – Allow multi-instance application

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s