Visual Studio 线程语句出错?

Visual Studio Thread Statement gives Error?

我反编译了一个 .NET 应用程序来编写我自己的注入软件。线程错误不想被删除。我什么都试过了,但它一直告诉我出了点问题...

Code (Screenshot)

{
    using System;
    using System.IO;
    using System.IO.Pipes;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Threading;
    using System.Windows.Forms;

    internal class NamedPipes
    {
        public static string luapipename = "IDUNNOPIPE123";

        public static void LuaPipe(string script)
        {
            if (NamedPipeExist(luapipename))
            {
                new Thread (delegate {
                    try
                    {
                        using (NamedPipeClientStream stream = new NamedPipeClientStream(".", luapipename, PipeDirection.Out))
                        {
                            stream.Connect();
                            using (StreamWriter writer = new StreamWriter(stream, Encoding.Default, 0xf423f))
                            {
                                writer.Write(script);
                                writer.Dispose();
                            }
                            stream.Dispose();
                        }
                    }
                    catch (IOException)
                    {
                        MessageBox.Show("Error occured connecting to the pipe.", "Connection Failed!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    catch (Exception exception1)
                    {
                        MessageBox.Show(exception1.Message.ToString());
                    }
                }).Start();
            }
            else
            {
                MessageBox.Show("Please Inject " + Functions.exploitdllname + " before Using this!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        public static bool NamedPipeExist(string pipeName)
        {
            bool flag;
            try
            {
                int timeout = 0;
                if (!WaitNamedPipe(Path.GetFullPath($"\\.\pipe\{pipeName}"), timeout))
                {
                    bool flag4;
                    int num2 = Marshal.GetLastWin32Error();
                    if (num2 != 0)
                    {
                        if (num2 != 2)
                        {
                            goto TR_0005;
                        }
                        else
                        {
                            flag4 = false;
                        }
                    }
                    else
                    {
                        flag4 = false;
                    }
                    return flag4;
                }
            TR_0005:
                flag = true;
            }
            catch (Exception)
            {
                flag = false;
            }
            return flag;
        }

        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
        private static extern bool WaitNamedPipe(string name, int timeout);
    }
}

我认为您遇到了 The call is ambiguous between the following methods or properties: 'Thread.Thread(ThreadStart)' and 'Thread.Thread(ParameterizedThreadStart)' 错误。

正如您正确指出的那样,编译器无法区分 Thread 构造函数参数的类型。 ParameterizedThreadStart is used if you pass a parameter to your delegate when calling the Thread.Start method. Your code does not do this. Thus, you need a ThreadStart 在这里委托。它的语法是

public delegate void ThreadStart();

即它不接受任何参数,也没有 return 值。所以,你可以传递一个 lambda function 做同样的事情。

new Thread(() => {
    // ...
}).Start();