C
C#2y ago
itgel9462

❔ Call a method

Hi. Can I call this Main method in another place by not creating an instance.
15 Replies
Florian Voß
Florian Voß2y ago
only if you make it static
itgel9462
itgel94622y ago
Sorry. I changed it static and tried to call the method. But I got an error.
Florian Voß
Florian Voß2y ago
try chaning async public to public async and see if it works then
Kiel
Kiel2y ago
make sure your Program class is public too
Angius
Angius2y ago
Don't use new Task() btw
Florian Voß
Florian Voß2y ago
whats the difference between doing Task task = StreamSample.StreamSampleMain() and Task task = new Task(StreamSample.StreamSampleMain)? if any
khamas
khamas2y ago
Make sure class is public, and use Task.Run
Pobiega
Pobiega2y ago
Task-based asynchronous programming - .NET
In this article, learn about task-based asynchronous programming through the Task Parallel Library (TPL) in .NET.
Pobiega
Pobiega2y ago
its usually recommended to use TaskFactory.StartNew if you need fine-grained control over your task
Florian Voß
Florian Voß2y ago
but wouldn't we resole the task using await task either way?
Pobiega
Pobiega2y ago
sure
Florian Voß
Florian Voß2y ago
so what's the diff
Pobiega
Pobiega2y ago
Task task = new Task(...);
task.Start();
await task();
Task task = new Task(...);
task.Start();
await task();
vs
Task task = AsyncStuff();
await task();
Task task = AsyncStuff();
await task();
Florian Voß
Florian Voß2y ago
oh okay tyvm
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server
More Posts