-1

So, I've written an import/export function on my application, and I have set a file extension associated with my application. When exporting reminders, it creates a .remindme file. This can be opened, and it is caught in my program.cs like this

        [STAThread]
        [HandleProcessCorruptedStateExceptions]
        static void Main(string[] args)
        {                       
            using (Mutex mutex = new Mutex(false, "Global\\" + "RemindMe"))
            {
                if (!mutex.WaitOne(0, false))
                {
                    if (args.Length > 0)
                    {//The user double-clicked an .remindme file while remindme is running!   

                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);
                        Application.Run(new Import(args[0]));
                    }
                    //one instance of remindme already running                                        
                    return;
                }

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);                
                Application.Run(new Form1());
            }    
        }

I tried making an new instance of Import(a windows-form) here, and doing Import.Show() , but that doesn't work. I've searched all over the place, and the only thing I found is by using Application.Run() on the form. This does indeed launch it, but it creates another instance of my application. This carries problems with it, including not being able to use the database.

When I double-click the .remindme file while the application is running, using a second Application.Run() the form successfully launches.

enter image description here

But, when I press yes(attempts to insert data into the database) it throws an EntityException

enter image description here

full stacktrace on pastebin

After some digging I found that I can't use two instances using the same SQLite database. This new form counts as a new instance, because I used Application.Run

So, in conclusion what I'm looking for is a way to launch a new form from program.cs (because that's where I catch the double-click on a .remindme file)

stefan
  • 165
  • 1
  • 15
  • What ? :) I've read you post and for me, it is something like this: "I've bought a new shirt, the game was great, my girlfriend is ugly, and i don't' know how to draw this painting. So my question is: "how can I be taller by 10 cm" – Piotr Aug 02 '17 at 21:45
  • is it really that bad? well i'll try to ask it in one line "How can i start a new windows-form when the main windows-form is already up, **from program.cs** ? note: `Application.Run()` doesn't seem to be an option though" – stefan Aug 02 '17 at 21:48
  • I'm not a guru in winforms. I don't have business experience. I have a little bit more experience with WPF (and MVVM) but still, it is hoppy experience (not the bussines one) If it was about WPF (and MVVM and caliburn.micro as a framework) I would suggest changing the screen to new screen and that would be it. Maybe you should discover new technologies (Winforms are somehow obsolete) – Piotr Aug 02 '17 at 21:58

1 Answers1

0

After a lot of searching, i came to a solution of sending a windows process message, and it works well!

I got it working using the example here

stefan
  • 165
  • 1
  • 15