Esempio n. 1
0
 /// <summary>
 /// 初始化通知和内存共享文件
 /// </summary>
 private void Init(bool read)
 {
     memoryFile = MemoryMappedFileHelper.CreateMemoryMappedFileObj(processKey + MemoryMappedFileNameTag);
     eventWait  = EventWaitHandleHelper.CreateEventHande(processKey + EventWaitNameTag, false);
     if (read)
     {
         Task.Factory.StartNew(WaitForMessage);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 是否已经在运行
 /// </summary>
 /// <param name="processKey">唯一标识</param>
 /// <param name="activeWindow">已经运行是否激活之前窗体</param>
 /// <returns></returns>
 public static bool HadRun(string processKey, bool activeWindow = false)
 {
     if (activeWindow)
     {
         var handelStr = MemoryMappedFileHelper.CreateMemoryMappedFileObj(processKey + handelTag).ReadData();
         if (!string.IsNullOrEmpty(handelStr))
         {
             var handel = (IntPtr)int.Parse(handelStr);
             Win32Helper.ShowWindowAsync(handel, SW_SHOWNOMAL);
             Win32Helper.SetForegroundWindow(handel);
         }
     }
     return(HadRun(processKey));
 }
Esempio n. 3
0
 /// <summary>
 /// 将当前主窗口 句柄写入到进程内存,方便激活
 /// </summary>
 /// <param name="processKey"></param>
 /// <param name="windowHandel"></param>
 public static void WriteHandel(string processKey, IntPtr windowHandel)
 {
     fileMapped = MemoryMappedFileHelper.CreateMemoryMappedFileObj(processKey + handelTag);
     fileMapped.WriteData(windowHandel.ToString());
 }