Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous threads and session

When a new async thread has been spawned using this signature, will the ASP.NET session object be available to the this new thread?

IAsyncResult asyncCall = f.BeginInvoke(null, f);
like image 381
Narmatha Balasundaram Avatar asked Feb 23 '11 20:02

Narmatha Balasundaram


People also ask

Does Async use threading?

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.

What is asynchronous thread pool?

A thread pool is a collection of worker threads that efficiently execute asynchronous callbacks on behalf of the application. The thread pool is primarily used to reduce the number of application threads and provide management of the worker threads.


1 Answers

I don't know about which session object you are talking about but if you talk about the ASP.NET Session it might not be available. Also it is bad practice to access the ASP.NET Session from background threads. I would recommend you passing an object containing all the necessary information to this background tread instead of having it pull stuff from a session => makes it less reusable.

Normally if the caller of this thread waits for it to complete the session should be available all along but honestly it's bad design and I would simply avoid it.

like image 134
Darin Dimitrov Avatar answered Sep 28 '22 12:09

Darin Dimitrov