Thang Le

Thang Le

  • NA
  • 6
  • 1.5k

[C# Windows Forms] Open form in static main

Feb 11 2019 10:22 PM
Hi everybody.
I have 2 form : MainFrm is main form and Notification is form used to show notification.
In program.cs :
  1. static void Main()  
  2. {  
  3. bool result;  
  4. Mutex mutex = new Mutex(true"UniqueAppId"out result);  
  5.   
  6. if (!result)  
  7. {  
  8. //MainFrm.showNotification("KyAppAPI??????????");  
  9.   
  10. //MessageBox.Show("KyAppAPI??????????");  
  11.   
  12. Notification notiBox = new Notification();  
  13. notiBox.Show();  
  14. return;  
  15. }  
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainFrm());
GC.KeepAlive(mutex);
}
[/CODE]

I use mutex to keep application run once. If application already running, form Notification will show.
But my code work not right, form Notification not shown.
In MainFrm, I has a static method showNotification (using Tulpep Notification). I try calling this method in static main, but it not working, too.
However, if I use MessageBox, it working fine.
I don't know where the problem is. Please help me.

Answers (3)