【发布时间】:2023-02-15 23:34:38
【问题描述】:
我在课堂上有这些方法
public async Task GetCompanies(int requestDuration, long startTimepoint)
{
_requestDuration = requestDuration;
_startTimepoint = startTimepoint;
Thread thread = new Thread(new ThreadStart(Test));
// This line doesnt compile - No overload for GetCompaniesApi matches delegate ThreadStart
Thread thread2 = new Thread(new ThreadStart(GetCompaniesApi));
}
public void Test()
{
}
public async Task GetCompaniesApi (int requestDuration, long? startTimepoint)
{
// code removed as not relevant
}
所以我的问题是如何在不同的线程中运行异步方法,我真的不知道“GetCompaniesApi 的重载不匹配委托 ThreadStart”是什么意思,或者我需要更改什么。
【问题讨论】:
-
直接管理线程有什么特别的原因吗?
标签: c# multithreading .net-7.0