Click here to Skip to main content
15,888,579 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to start a form without being activated? Pin
alin121-Oct-17 11:40
alin121-Oct-17 11:40 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre21-Oct-17 12:28
professionalSascha Lefèvre21-Oct-17 12:28 
GeneralRe: How to start a form without being activated? Pin
alin121-Oct-17 13:54
alin121-Oct-17 13:54 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre21-Oct-17 20:59
professionalSascha Lefèvre21-Oct-17 20:59 
GeneralRe: How to start a form without being activated? Pin
alin122-Oct-17 1:57
alin122-Oct-17 1:57 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre22-Oct-17 2:07
professionalSascha Lefèvre22-Oct-17 2:07 
GeneralRe: How to start a form without being activated? Pin
alin122-Oct-17 2:17
alin122-Oct-17 2:17 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre22-Oct-17 2:51
professionalSascha Lefèvre22-Oct-17 2:51 
Well, this is awkward. For testing, I commented the ShowWithoutActivation-override. As expected, it did activate then. Then I removed the comments and it still activates. I don't know what's happening there.

However, I have another solution for you:

1) Go to this article and download the code: All Three Features of Single-Instance Applications at One Shot, .NET[^]

2) Copy the files IRemoteFileLoader.cs, Server.cs and SingleInstanceManager.cs to your project folder.

3) Include them into your project (Project > Add existing item)

4) Add a reference to the System.Runtime.Remoting-assembly to your project (Project > Add reference).

5) Replace the code of your Program.cs by this:
C#
using System;
using System.Windows.Forms;
using SA.Universal.SingleInstance;

namespace FileArranger
{
	internal sealed class Program
	{
		[STAThread]
		static void Main(string[] commandLine)
		{
            if (SingleInstanceManager.IsSecondInstance)
            {
                SingleInstanceManager.HandleRemoteCommandLine(commandLine);
                SingleInstanceManager.ActivateFirstInstance();
                return;
            }

            Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
		}
	}
}
6) Add a using-Directive to your MainForm.cs:
C#
using SA.Universal.SingleInstance;
7) Add this to the constructor of MainForm:
C#
SingleInstanceManager.FilesLoading += (sender, eventArgs) => {
    Invoke(new System.Action(() => ReadArguments(eventArgs.CommandLine)));
};

That should do it.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson


modified 22-Oct-17 9:04am.

GeneralRe: How to start a form without being activated? Pin
alin122-Oct-17 3:22
alin122-Oct-17 3:22 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre22-Oct-17 3:33
professionalSascha Lefèvre22-Oct-17 3:33 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre22-Oct-17 3:35
professionalSascha Lefèvre22-Oct-17 3:35 
GeneralRe: How to start a form without being activated? Pin
alin122-Oct-17 4:14
alin122-Oct-17 4:14 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre22-Oct-17 4:19
professionalSascha Lefèvre22-Oct-17 4:19 
GeneralRe: How to start a form without being activated? Pin
Sascha Lefèvre22-Oct-17 5:11
professionalSascha Lefèvre22-Oct-17 5:11 
GeneralRe: How to start a form without being activated? Pin
alin122-Oct-17 5:53
alin122-Oct-17 5:53 
AnswerRe: How to start a form without being activated? Pin
Eddy Vluggen21-Oct-17 12:56
professionalEddy Vluggen21-Oct-17 12:56 
GeneralRe: How to start a form without being activated? Pin
alin121-Oct-17 14:22
alin121-Oct-17 14:22 
GeneralRe: How to start a form without being activated? Pin
Dave Kreskowiak22-Oct-17 2:03
mveDave Kreskowiak22-Oct-17 2:03 
GeneralRe: How to start a form without being activated? Pin
alin122-Oct-17 2:12
alin122-Oct-17 2:12 
GeneralRe: How to start a form without being activated? Pin
Eddy Vluggen23-Oct-17 8:32
professionalEddy Vluggen23-Oct-17 8:32 
AnswerRe: How to start a form without being activated? Pin
BillWoodruff21-Oct-17 16:54
professionalBillWoodruff21-Oct-17 16:54 
GeneralRe: How to start a form without being activated? Pin
alin122-Oct-17 2:03
alin122-Oct-17 2:03 
GeneralRe: How to start a form without being activated? Pin
Dave Kreskowiak22-Oct-17 2:18
mveDave Kreskowiak22-Oct-17 2:18 
GeneralRe: How to start a form without being activated? Pin
alin122-Oct-17 2:54
alin122-Oct-17 2:54 
GeneralRe: How to start a form without being activated? Pin
Dave Kreskowiak22-Oct-17 8:54
mveDave Kreskowiak22-Oct-17 8:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.