I am creating a WinForm application (.Net-5, .Net Core). The instance of my WinForm could be minimized/Hidden. Whenever I start my application, I need to check if there is an existing instance of the application already running. If there is already an existing instance then, I need to display its WinForm instead of creating new one.
In the code below, I am always checking if there is an existing process. If yes, how can I display open its Form/GUI?
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
var runningProcess = System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location));
if (runningProcess.Length>1) // Already running processes
{
//Get our previous instance
Process myProcess = runningProcess[0];
//How to SHOW the already exisitng (but minimized) instance of the Form?
//--?
//--?
}
else
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyGUI());
}
}