In winforms development you may create a BackgroundWorker
to avoid locking the UI on a long running process. In ASP.NET a POST/GET basically freezes until completion. I don't see how adding a Thread
would be of any benefit to this process. Maybe if the Thread
would speed completion (say on a multi-core server) it could help speed things up.
In the general sense I could use AJAX to make long calls without causing a "freeze" of the web page. In this sense AJAX can be thought of as a substitute for threading.
Is that it? Is threading pretty much useless on ASP.NET?
ASP.NET platform is multithreaded by its nature and provides programming models that shield us from the complexity of using threads.
Along with this, C# provides an option to execute the code that can be run in parallel using a multithreading concept, where the process/application can have multiple threads invoked within it.
Multithreading also leads to minimization and more efficient use of computing resources. Application responsiveness is improved as requests from one thread do not block requests from other threads. Additionally, multithreading is less resource-intensive than running multiple processes at the same time.
Multithreading is a feature provided by the operating system that enables your application to have more than one execution path at the same time. Multithreading is a feature provided by the operating system that enables your application to have more than one execution path at the same time.
Multithreading can make requests faster if:
In that case, you can indeed use multithreading in ASP.NET. A common mistake that people make is to spawn off threads and then not wait for them to complete- for instance "I am going to respond to the user while logging their purchase to the database on a background thread. This is always a bad idea, because IIS can and will recycle the Application Pool that your website is running in, and those background threads might be silently aborted.
Threading can be useful in server side programming if you need to return a response and don't want to tie up the server thread, in particular for long running processes that would cause the request to time out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With