1

I created my WPF single instance app by using the Microsoft.VisualBasic dll method. However I'm facing some difficulty to get the file path for second clicked file which associated with my app.

For example, I have two file "First.my" and "Second.my". When I click on file "First.my" it will launch my app and pop up message box to show "First.my" file path. Since my app is single instance app, when I click on file "Second.my" it should show the file path for "Second.my" but it still showing the file path for "First.my"..

Does anyone know how to pass the associate file path in single instance app?

Below is my code:

class WindowsFormsApp : Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
{
    private App _wpfApp;

    public WindowsFormsApp()
    {
        IsSingleInstance = true;
    }

    protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
    {
        MessageBox.Show("First File");
        //Get 1st click file path
        GetFilePath();
        _wpfApp = new App();
        _wpfApp.Run();

        return false;
    }

    protected override void OnStartupNextInstance(Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs e)
    {
        MessageBox.Show("Second File");
        //Get 2nd click file path
        GetFilePath(); 
    }

    protected void GetFilePath()
    {
        if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null &&
           AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0)
        {
            var filePath = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0];
            var uri = new Uri(filePath);
            MessageBox.Show(uri.LocalPath);
        }
    }
}
Jack
  • 79
  • 1
  • 8
  • don't you get second file information in `StartupNextInstanceEventArgs.CommandLine`? – YK1 Oct 25 '13 at 15:15
  • no.. nothing in StartupNextInstanceEventArgs.CommandLine – Jack Oct 26 '13 at 05:47
  • what did you do to associate `*.my` to your application? – YK1 Oct 26 '13 at 11:06
  • i just follow the steps in here. http://msdn.microsoft.com/en-us/library/bb892924.aspx – Jack Oct 27 '13 at 01:46
  • `WindowsFormsApplicationBase` uses `commandLine` to pass command line arguments to the `already running` single instance. Unfortunately, `ClickOnce` does not use command line to launch application with associated file. I am afraid, you may have to change either your deployment strategy or single instance strategy. – YK1 Oct 27 '13 at 19:25
  • http://stackoverflow.com/questions/248721/how-can-i-build-a-single-instance-application-using-click-once – YK1 Oct 27 '13 at 19:25

0 Answers0