public static void Main() { bool createNew; using (System.Threading.Mutex mutex = new System.Threading.Mutex(true, ProductName, out createNew)) { if (/*true ||*/ createNew) { ManageLiteAV.CrashDump dump = new ManageLiteAV.CrashDump(); dump.open(); SetProcessDPIAware(); // 默认关闭高DPI,避免SDK录制出错 Log.Open(); // 初始化SDK的 Local 配置信息 DataManager.GetInstance().InitConfig(); Process processes = Process.GetCurrentProcess(); Log.I(String.Format("Progress <{0}, {1}>", processes.ProcessName, processes.Id)); CloudDesktop.App app = new CloudDesktop.App(); app.InitializeComponent(); app.Run(); // 退出程序前写入最新的 Local 配置信息。 DataManager.GetInstance().Uninit(); DataManager.GetInstance().Dispose(); Log.Close(); dump.close(); } else { IpcClientChannel channel = new IpcClientChannel(); if (channel != null) { try { ChannelServices.RegisterChannel(channel, false); WndHandle obj = (WndHandle)Activator.GetObject(typeof(WndHandle), "ipc://" + ProductName + "ServerChannel" + "/WindowsHandle"); if (obj != null) { IntPtr nWndHandle = obj.GetWndHandle(); ShowWindowAsync(nWndHandle, SW_SHOWNOMAL); //显示 SetForegroundWindow(nWndHandle); //当到最前端 } ChannelServices.UnregisterChannel(channel); } catch (Exception) { } } } } }
private void RegIpcServer() { try { WndHandle.SetWnd(new WindowInteropHelper(this).Handle); m_IpcServerChannel = new IpcServerChannel(ProductName + "ServerChannel"); if (m_IpcServerChannel != null) { ChannelServices.RegisterChannel(m_IpcServerChannel, false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(WndHandle), "WindowsHandle", WellKnownObjectMode.SingleCall); } } catch (Exception) { } }