(I use the term “asynchronously” loosely in the subject)
I’ve been using the below code for a while to save initial session context info to the DB such as affiliate details for later tracking. I’ve suggested others to use this concept to speed up some of their processes but i’d hate to be suggesting something that is potentially dangerous.
I’d like to know if this is acceptable or are there some threading issues i’ll be causing later down the road on peak traffic times?
new Thread(() => {
//All my logic for saving info to DB
})
{ Name = "My long running page process", IsBackground = true, Priority = ThreadPriority.Normal }.Start();
UPDATE
Thanks!
After David Basarab’s answer, I think this will be my new method:
Action someLongProcess = () =>
{
// You DB Work
};
someLongProcess.BeginInvoke((x) => {
someLongProcess.EndInvoke(x);
// It is now done you can do something
}, null);
I would use the thread pool. Because it gives uses a predefeined pools of threads, rather than create a new one for each request. And it gives you the true Async by exposing a callback.
You can just use the Action delegate and call the BeginInvoke which uses the thread pool in the background.