我想知道,如何在线程池中运行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#程序执行的所有可能性?
I wonder, how can I run the method Main() of C# program in the thread pool like I do it in F#:
let main() = Console.WriteLine("Hello World!") do Task.Factory.StartNew(main).Wait()What is the alternative code in C# programming language? 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 questionAnd I can't somewhere also add smth like in F#:
do Task.Factory.StartNew(main).Wait()Or I just don't know the all possibilites of C# program execution?
最满意答案
我可以建议你不要那样做。 我很确定你应该编写其他函数,然后可以根据需要添加到线程池中。
在大多数编程语言中,调用main函数是不好的方式; 如果您想要这样做,请编写其他功能来完成您的工作。 基本上:
static void Function(){ //Do stuff } static void Main(){ TaskFactory.StartNew(Function).wait(); }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; 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(); }
更多推荐
发布评论