public void Run(EasyHook.RemoteHooking.IContext context, String channelName, ConfigDll config) { //Если не использовать GAC, могут возникать проблемы с правильной организацией удаленных сборок. //Это обходной путь, который гарантирует, что текущая сборка правильно связана AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += (sender, args) => { return(this.GetType().Assembly.FullName == args.Name ? this.GetType().Assembly : null); }; var curProcess = Process.GetCurrentProcess(); NativeMethods.MessageBox(curProcess.MainWindowHandle.ToString()); //NativeMethods.SendMessage(handle, NativeMethods.WM_CLOSE, IntPtr.Zero, IntPtr.Zero); // NOTE: This is running in the target process _interface.Message("Injected into process Id: " + RemoteHooking.GetCurrentProcessId().ToString()); _runWait = new System.Threading.ManualResetEvent(false); _runWait.Reset(); try { // point to Initialise the Hook // Initialise the Hook if (!InitialiseDirectXHook(config)) { return; } _interface.Disconnected += _clientEventProxy.DisconnectedProxyHandler; _clientEventProxy.Disconnected += () => { // We can now signal the exit of the Run method _runWait.Set(); }; // We start a thread here to periodically check if the host is still running // If the host process stops then we will automatically uninstall the hooks StartCheckHostIsAliveThread(); // Wait until signaled for exit either when a Disconnect message from the host // or if the the check is alive has failed to Ping the host. _runWait.WaitOne(); // we need to tell the check host thread to exit (if it hasn't already) StopCheckHostIsAliveThread(); // point of disposin all threads //NativeMethods.MessageBox("Disposing"); } catch (Exception e) { _interface.Message("Method \"Run\". An unexpected error occured: " + e.ToString()); } finally { try { _interface.Message("Disconnecting from process " + EasyHook.RemoteHooking.GetCurrentProcessId()); } catch { } // Remove the client server channel (that allows client event handlers) ChannelServices.UnregisterChannel(_clientServerChannel); // Always sleep long enough for any remaining messages to complete sending System.Threading.Thread.Sleep(100); } }