public static bool send_thread(string process_name, int type, string msg) { tag_send_msg str_msg = new tag_send_msg(); str_msg.m_processName = process_name; str_msg.m_type = type; str_msg.m_msg = msg; Thread thread = new Thread(new ParameterizedThreadStart(ThreadFunc)); thread.IsBackground = true; thread.Start(str_msg); return(true); }
protected static void ThreadFunc(object obj) { tag_send_msg str_msg = (tag_send_msg)obj; IntPtr receiver_handler = FindWindow(null, str_msg.m_processName); if (IntPtr.Zero == receiver_handler) { return; } byte[] sarr = System.Text.Encoding.Default.GetBytes(str_msg.m_msg); int len = sarr.Length; COPYDATASTRUCT cds; cds.dwData = (IntPtr)Convert.ToInt16(str_msg.m_type); cds.cbData = len + 1; cds.lpData = str_msg.m_msg; SendMessage(receiver_handler, WM_COPYDATA, 0, ref cds); }