Async methods are intended to be non-blocking operations. An await expression in an async method doesn’t block the current thread while the awaited task is running. Instead, the expression signs up the rest of the method as a continuation and returns control to the caller of the async method.
The async and await keywords don't cause additional threads to be created. Async methods don't require multithreading because an async method doesn't run on its own thread. The method runs on the current synchronization context and uses time on the thread only when the method is active. You can use Task.Run to move CPU-bound work to a background thread, but a background thread doesn't help with a process that's just waiting for results to become available.
The async-based approach to asynchronous programming is preferable to existing approaches in almost every case. In particular, this approach is better than BackgroundWorker for IO-bound operations because the code is simpler and you don't have to guard against race conditions. In combination with Task.Run, async programming is better than BackgroundWorker for CPU-bound operations because async programming separates the coordination details of running your code from the work that Task.Run transfers to the threadpool.
I said
Quote:
|
Not using "await Task.Run()"
|
You can run tasks on one thread. Task.Start(Scheduler) if done properly will use only one thread. You can verify by using a loop and print out the managed thread id. They complete in a different order than being executed which also implies that they run "at the same time", asynchronusly.
I have my own pool of 6 Threads that do everything. The only Threadpool usage would be the BeginXX EndXX Sockets since they use the threadpool internally. I run 6 threads with sync contexts and queues that allow me to shoot tasks on them and utilize each thread efficiently. Each thread has a given "core task": PacketQueue In / Out, Mobs, Players, Map and Item. All those threads get tasks shot at them and they work pretty nicely parallel.
Since every packethandler is a task, a active server should have a high change in active threads if they were spawning / utilizing threadpool threads yes?
I appreciate your feedback Korvacs since you have experience in running servers as opposed to fang.