gpt4 book ai didi

c# - 使用线程异步执行 C# 方法

转载 作者:行者123 更新时间:2023-11-30 14:15:53 24 4
gpt4 key购买 nike

我在类中有一个方法需要异步执行两次。该类有一个接受 URL 作为参数的构造函数:

ABC abc= new ABC(Url);

// Create the thread object, passing in the abc.Read() method
// via a ThreadStart delegate. This does not start the thread.
Thread oThread = new Thread(new ThreadStart(abc.Read());


ABC abc1= new ABC(Url2)

// Create the thread object, passing in the abc.Read() method
// via a ThreadStart delegate. This does not start the thread.
Thread oThread1 = new Thread(new ThreadStart(abc1.Read());

// Start the thread
oThread.Start();
// Start the thread
oThread1.Start();

这是它的工作方式吗?谁能帮忙?

最佳答案

删除括号以创建委托(delegate):

Thread oThread = new Thread(new ThreadStart(abc.Read));

oThread1 做同样的事情。这是 MSDN's Delegates Tutorial .

关于c# - 使用线程异步执行 C# 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8992779/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com