So i have recently been working on optimizing an app im developing for work, however i have run into a question i havnt found a satisfactory answer for:
is it ok to use thread rather than task.run()?
ive only had to use e.g.: new thread(new threadstart(()=>{ //blah })); a couple of times, it just worked better and yielded a faster load time.
only reason i ask is everyone says use task.run(), and i tried, but thread just provided a much smoother result.
Thank you for your time!
I think it is better to use Task
than Thread
.
only reason i ask is everyone says use task.run(), and i tried, but thread just provided a much smoother result.
You could consider Task
as a promise. And Thread
is a way of fulfilling that promise.
Not all Task
need a Thread
to run. And create a thread is much more expensive than re-using an existing thread from the threadpool.
You could refer to following links for more information:
https://stackoverflow.com/questions/13429129/task-vs-thread-differences
https://stackoverflow.com/a/4130347/7063418
Answers
I think it is better to use
Task
thanThread
.You could consider
Task
as a promise. AndThread
is a way of fulfilling that promise.Not all
Task
need aThread
to run. And create a thread is much more expensive than re-using an existing thread from the threadpool.You could refer to following links for more information:
https://stackoverflow.com/questions/13429129/task-vs-thread-differences
https://stackoverflow.com/a/4130347/7063418