[英]How to run Main() method from C# program in the thread pool?
我想知道,如何在線程池中運行C#程序的Main()
方法,就像我在F#中一樣:
let main() =
Console.WriteLine("Hello World!")
do Task.Factory.StartNew(main).Wait()
C#編程語言中的替代代碼是什么? 因為在簡單的控制台應用程序中,只有使用方法:
static void Main() // or with int as the return type and args[]
// in method arguments but it's not important for this question
我不能在某處添加像F#中的smth:
do Task.Factory.StartNew(main).Wait()
或者我只是不知道C#程序執行的所有可能性?
我可以建議你不要那樣做。 我很確定你應該編寫其他函數,然后可以根據需要添加到線程池中。
在大多數編程語言中,調用main函數是不好的方式; 如果您想要這樣做,請編寫其他功能來完成您的工作。 基本上:
static void Function(){
//Do stuff
}
static void Main(){
TaskFactory.StartNew(Function).wait();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.