❔ Call a method
Hi. Can I call this Main method in another place by not creating an instance.
15 Replies
only if you make it
static
Sorry. I changed it static and tried to call the method. But I got an error.
try chaning
async public
to public async
and see if it works thenmake sure your Program class is public too
Don't use
new Task()
btwwhats the difference between doing
Task task = StreamSample.StreamSampleMain()
and Task task = new Task(StreamSample.StreamSampleMain)
?
if anyMake sure class is public, and use Task.Run
with
new Task
you have to remember to start the task yourself. Look at https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-based-asynchronous-programming#creating-and-running-tasks-explicitly for more infoTask-based asynchronous programming - .NET
In this article, learn about task-based asynchronous programming through the Task Parallel Library (TPL) in .NET.
its usually recommended to use TaskFactory.StartNew if you need fine-grained control over your task
but wouldn't we resole the task using
await task
either way?sure
so what's the diff
vs
oh okay
tyvm
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.