public static void SendGlobalMessage(IpcParamEx ipcMsg) { if (ipcMsg == null) { throw new ArgumentNullException("ipcMsg"); } int nId = (int)(MemUtil.BytesToUInt32(CryptoRandom.Instance.GetRandomBytes( 4)) & 0x7FFFFFFF); if (WriteIpcInfoFile(nId, ipcMsg) == false) { return; } try { // NativeMethods.SendMessage((IntPtr)NativeMethods.HWND_BROADCAST, // Program.ApplicationMessage, (IntPtr)Program.AppMessage.IpcByFile, // (IntPtr)nId); // IntPtr pResult = new IntPtr(0); // NativeMethods.SendMessageTimeout((IntPtr)NativeMethods.HWND_BROADCAST, // Program.ApplicationMessage, (IntPtr)Program.AppMessage.IpcByFile, // (IntPtr)nId, NativeMethods.SMTO_ABORTIFHUNG, 5000, ref pResult); IpcBroadcast.Send(Program.AppMessage.IpcByFile, nId, true); } catch (Exception) { Debug.Assert(false); } RemoveIpcInfoFile(nId); }
private static string GetMutexPath(string strName) { string strDir = UrlUtil.EnsureTerminatingSeparator( UrlUtil.GetTempPath(), false); return(strDir + IpcUtilEx.IpcMsgFilePreID + IpcBroadcast.GetUserID() + "-Mutex-" + strName + ".tmp"); }
public static void SendGlobalMessage(IpcParamEx ipcMsg, bool bOneInstance) { if (ipcMsg == null) { throw new ArgumentNullException("ipcMsg"); } int nId = (int)(MemUtil.BytesToUInt32(CryptoRandom.Instance.GetRandomBytes( 4)) & 0x7FFFFFFF); if (!WriteIpcInfoFile(nId, ipcMsg)) { return; } try { // NativeMethods.SendMessage((IntPtr)NativeMethods.HWND_BROADCAST, // Program.ApplicationMessage, (IntPtr)Program.AppMessage.IpcByFile, // (IntPtr)nId); // IntPtr pResult = new IntPtr(0); // NativeMethods.SendMessageTimeout((IntPtr)NativeMethods.HWND_BROADCAST, // Program.ApplicationMessage, (IntPtr)Program.AppMessage.IpcByFile, // (IntPtr)nId, NativeMethods.SMTO_ABORTIFHUNG, 5000, ref pResult); IpcBroadcast.Send(bOneInstance ? Program.AppMessage.IpcByFile1 : Program.AppMessage.IpcByFile, nId, true); } catch (Exception) { Debug.Assert(false); } if (bOneInstance) { string strIpcFile = GetIpcFilePath(nId); for (int r = 0; r < 50; ++r) { try { if (!File.Exists(strIpcFile)) { break; } } catch (Exception) { Debug.Assert(false); } Thread.Sleep(20); } } else { Thread.Sleep(1000); } RemoveIpcInfoFile(nId); }