C#
C#

help

Root Question Message

Itgel
Itgel2/18/2023
❔ Call a method

Hi. Can I call this Main method in another place by not creating an instance.
Florian Voß
Florian Voß2/18/2023
only if you make it static
Itgel
Itgel2/18/2023
Sorry. I changed it static and tried to call the method. But I got an error.
Florian Voß
Florian Voß2/18/2023
try chaning async public to public async and see if it works then
Kiel
Kiel2/18/2023
make sure your Program class is public too
Angius
Angius2/18/2023
Don't use new Task() btw
Florian Voß
Florian Voß2/19/2023
whats the difference between doing Task task = StreamSample.StreamSampleMain() and Task task = new Task(StreamSample.StreamSampleMain)?
Florian Voß
Florian Voß2/19/2023
if any
flkXI
flkXI2/19/2023
Make sure class is public, and use Task.Run
Pobiega
Pobiega2/19/2023
Pobiega
Pobiega2/19/2023
its usually recommended to use TaskFactory.StartNew if you need fine-grained control over your task
Florian Voß
Florian Voß2/19/2023
but wouldn't we resole the task using await task either way?
Pobiega
Pobiega2/19/2023
sure
Florian Voß
Florian Voß2/19/2023
so what's the diff
Pobiega
Pobiega2/19/2023
Task task = new Task(...);
task.Start();
await task();

vs
Task task = AsyncStuff();
await task();
Florian Voß
Florian Voß2/19/2023
oh okay
Florian Voß
Florian Voß2/19/2023
tyvm
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy