2010-01-08 81 views

回答

0

您可以使用Windows消息。詳情請見blog post

+0

嘿我試過使用窗口消息,它的罰款,如果我們有一個特定名稱的單個窗口.. 但如果我們有多個相同名稱的窗口? – Naruto 2010-01-08 13:27:36

1

編輯:

錯過了的問題是關於移動。不知道這是否有效。

我使用IPC信道與此輔助類:

static class IpcChannelManager<T> { 
    /// <summary> 
    /// Make a type available to other processess 
    /// </summary> 
    /// <param name="type"> 
    /// Type to register, must derive from MarshalByRefObject and implement <typeparamref name="T"/> 
    /// </param> 
    /// <param name="portName">Name of IpcChannel</param> 
    public static void RegisterType(Type type, string portName) { 
     if (!type.IsSubclassOf(typeof(MarshalByRefObject))) 
      throw new ArgumentException("Registered type must derive from MarshalByRefObject"); 
     Dictionary<string, string> ipcproperties = new Dictionary<string, string>(); 
     ipcproperties["portName"] = portName; 
     // Get the localized name of the "Authenticated users" group 
     ipcproperties["authorizedGroup"] = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null).Translate(typeof(NTAccount)).ToString(); 

     ChannelServices.RegisterChannel(new IpcServerChannel(ipcproperties, null), false); 
     RemotingConfiguration.RegisterWellKnownServiceType(type, typeof(T).Name, WellKnownObjectMode.Singleton); 
    } 

    /// <summary> 
    /// Get a reference to a remoting object 
    /// </summary> 
    /// <param name="portName">Name of Ipc port</param> 
    /// <returns> 
    /// Reference to remote server object</returns> 
    public static T GetRemoteProxy(string portName) { 
     ChannelServices.RegisterChannel(new IpcClientChannel(), false); 
     return (T)Activator.GetObject(typeof(T), "ipc://" + portName + "/" + typeof(T).Name); 
} 

然後我使用它是這樣的:

一個可用的兩側界面

interface IIpcMessage { 
    int GetSomeData(string foo); 
} 

在接收端我做

class IpcMessage : MarshalByRefObject, IIpcMessage { 
    ... 
} 

IpcChannelManager<IIpcMessage>.RegisterType(typeof(IpcMessage), "Someuniqueportname"); 

而且在發送端:

IIpcMessage ipcMessage = IpcChannelManager<IIpcMessage>.GetRemoteProxy("Someuniqueportname"); 

int data = ipcMessage.GetSomeDate("blabla"); 
+0

這不適用於Windows Mobile/Windows CE – ctacke 2010-01-08 19:57:04

1

的CreateProcess可以返回進程句柄。所有你需要做的就是WaitForSinbleObject,它將在.NET進程退出時發出信號。

+0

嘿我們應該能夠通過命令行中的事件句柄.. 是否有可能? – Naruto 2010-01-08 10:33:02

+0

是的,你可以通過命令行傳遞東西。但是,不處理值,它們的值僅在創建它們的過程中有效。 – 2010-01-08 11:54:12

+0

嘿..在命令行我們可以通過字符串.. 我們如何能夠通過事件句柄.. 可以嗎?請告訴我 – Naruto 2010-01-08 13:43:05

相關問題