0
我創建了一個帶參數和返回值的函數。這是下面的代碼:帶返回值和參數的C#傳遞函數Thread
static void Main(string[] args)
{
string url = "URL";
Thread thread = new Thread(
() => readFile(url)
);
thread.Start();
}
public static bool readFile(string url)
{
bool result = true;
return result;
}
我怎麼能從線程內部的方法返回值?
您可能需要傳遞迴調。我會考慮尋找像TPL這樣的更高層次的東西('任務'),也許'異步/等待'來做到這一點。如果你真的從url中讀取文件,那麼'HttpClient'上有異步方法。 –