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.
But, when I press yes(attempts to insert data into the database) it throws an EntityException
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)