c# - Visual Studio Thread Statement gives Error?
问题描述
I decompiled a .NET Application to write my own Injection Software. A Thread Error don't want to get removed. I tried everything but it keeps telling me that something is wrong...
{
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);
}
}
解决方案
I think you are getting the The call is ambiguous between the following methods or properties: 'Thread.Thread(ThreadStart)' and 'Thread.Thread(ParameterizedThreadStart)'
error with this.
As you correctly noted, the compiler can't distinguish what type the Thread
constructor parameter is. 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 delegate here. Its syntax is
public delegate void ThreadStart();
I.e. it does not accept any parameter and does not return a value. So, you can just pass a lambda function that does the same.
new Thread(() => {
// ...
}).Start();
推荐阅读
- python - Python FTP 检索打破了 FOR 循环。我用 try-catch 块修复了它。为什么它有效?
- python - Kivy app AttributeError:“int”对象没有属性“value”
- node.js - 从客户端从 mongoDB 中删除项目
- c - 为什么循环迭代少于声明?
- mysql - 颤振和json:NoSuchMethodError:方法'[]'在null上被调用
- python - 以插入模式打印python
- ruby-on-rails - Ruby选择随机文件
- python - 具有许多类的 BERT 模型分类
- scala - 通过 PathMatchers 从 akka-http 中的 uri 路径中提取两个段值的惯用方法是什么?
- android - 如何从 viewModelScope Android 获取响应变量