[英]How to run Main() method from C# program in the thread pool?
I wonder, how can I run the method Main()
of C# program in the thread pool like I do it in F#: 我想知道,如何在线程池中运行C#程序的
Main()
方法,就像我在F#中一样:
let main() =
Console.WriteLine("Hello World!")
do Task.Factory.StartNew(main).Wait()
What is the alternative code in C# programming language? C#编程语言中的替代代码是什么? Because in the simple console application, there is only the way to use:
因为在简单的控制台应用程序中,只有使用方法:
static void Main() // or with int as the return type and args[]
// in method arguments but it's not important for this question
And I can't somewhere also add smth like in F#: 我不能在某处添加像F#中的smth:
do Task.Factory.StartNew(main).Wait()
Or I just don't know the all possibilites of C# program execution? 或者我只是不知道C#程序执行的所有可能性?
Could I suggest that you refrain from that. 我可以建议你不要那样做。 I'm fairly certain that you should write other functions which you can then add to the thread pool as required.
我很确定你应该编写其他函数,然后可以根据需要添加到线程池中。
In most programming languages, it's bad style to call the main function; 在大多数编程语言中,调用main函数是不好的方式; write other functions to do your work if that's how you want to do it.
如果您想要这样做,请编写其他功能来完成您的工作。 Basically:
基本上:
static void Function(){
//Do stuff
}
static void Main(){
TaskFactory.StartNew(Function).wait();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.