Maximize application in system tray?

你说的曾经没有我的故事 提交于 2019-12-03 13:17:00
Conrad Frix

This answer from Jon Skeet discusses using a mutex to do it

Mutex is the way to go. It's a lot less fragile than using process names etc.

However, you need to make sure the Mutex isn't garbage collected. In the case of a service (which is event driven rather than having a "main" method which runs to completion), the most sensible way of doing this is probably to put it in a static variable.

Dispose of the mutex when the service stops, so you don't need to wait for finalization or anything like that.

Matthew Brindley gives this example in the same question for his answer

[STAThread]
static void Main() 
{
   using(Mutex mutex = new Mutex(false, "Global\\" + appGuid))
   {
      if(!mutex.WaitOne(0, false))
      {
         MessageBox.Show("Instance already running");
         return;
      }

      Application.Run(new Form1());
   }
}

To maximize the other application you'll need to send it the message to maximize. See this article on message sending

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!