gpt4 book ai didi

asp.net - 线程与参数化ThreadStart

转载 作者:行者123 更新时间:2023-12-03 13:00:53 25 4
gpt4 key购买 nike

我是.NET的新手。我在我的项目中使用线程。请在下面检查我的代码-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication6
{
class Program
{
private void Amadeus(object str)
{
Console.WriteLine(str.ToString());
}

static void Main(string[] args)
{
Program objClass = new Program();

//One way to call Amadeus Method...
Thread objThread = new Thread(objClass.Amadeus);
objThread.Start("Amadeus without ParameterizedThreadStart");

//Other way to call Amadeus Method...
ParameterizedThreadStart objParamThread = new ParameterizedThreadStart(objClass.Amadeus);
Thread ObjThreadParam = new Thread(objParamThread);
ObjThreadParam.Start("Amadeus with ParameterizedThreadStart");

Console.ReadLine();
}
}

}

能否请您告诉我,上述两种方式都在做相同的工作,所以两者之间有什么区别?

提前致谢。

最佳答案

两者都是一样的。阅读MSDN documentation

Visual Basic and C# users can omit the ThreadStart or ParameterizedThreadStart delegate constructor when creating a thread. In Visual Basic, use the AddressOf operator when passing your method to the Thread constructor; for example, Dim t As New Thread(AddressOf ThreadProc). In C#, simply specify the name of the thread procedure. The compiler selects the correct delegate constructor.

关于asp.net - 线程与参数化ThreadStart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8486989/

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