简体   繁体   中英

C# - Server/Client multithreaded or async

Should my C# UI, Client/Server application be multi threaded or asynchronous? Now I have made it with multithreading. But is that the correct way? Should I change it to an async-await pattern?

Hi the asyn/await pattern is the best option over multithreading. With this pattern even though the code runs asynchronously, no new threads are created. It uses an underlying state machine to achieve asynchronous nature. This is good when you are dealing with client/ server applications where all the requests run in thread pool threads. Spinning up a new thread means you may end up serving less requests (as requests will be queued for threads). With asynchronous calls you will serve more number of requests per second as the threads are not blocked during the long running I/O or network calls. Please let me know if you have more questions. Thank you

If it is a client GUI application, I would go for the async-await approach. It feels more "natural" using async-await in the GUI context. I've programmed a Xamarin forms app fetching db entries from a db in azure, and it was simple to do this with async-await.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM