0

我正在尝试从主线程向 C# wpf 中的后台发送一条消息。

后台线程如下:

        public class LoopThread()
        {
            public void Start()
            {
                User32.MSG msg;
                sbyte ret;
                while(true)
                {
                    ret = User32.GetMessage(out msg, IntPtr.Zero, 0, 0);
                    //Here the debugger never reaches
                    ......
                }
            }
        }

和主线程:

            LoopThread loop = new LoopThread();
            Thread threadLoop = new Thread(loop.Start);
            threadLoop.Start();

            Thread.Sleep(100);

            bool postResult = User32.PostThreadMessage(
                Convert.ToUInt32(threadLoop.ManagedThreadId),
                WM_USER + 1,
                UIntPtr.Zero,
                IntPtr.Zero);

但是postResult == false。并GetLastWin32Error返回ERROR_INVALID_THREAD_ID

那么,错在哪里呢?

4

0 回答 0