Developer forum

Forum » Development » Parallel tasks

Parallel tasks

Peter Leleulya
Reply

I would like to be able to do a parallel task, for example pre caching products on login.
It seems that a null reference exception occurs as soon as a Dynamicweb function is called, so it seems to have lost its context.
I’ve tried everything I could find. (parallel.invoke, async handler, threading, etc)
Does anyone have any best practices on that?


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Peter

Usually that is not possible or hard to implement because Dynamicweb is depending on the httpcontext which is not available in a thread. But if you pass the httpcontext of the user triggering the new thread to the thread you are spawning, it should be possible.

Here is an example:

http://stackoverflow.com/questions/8109526/the-cross-thread-usage-of-httpcontext-current-property-and-related-things

But it is not a problem free approach with long running threads etc. But it works for many scenarios.

Hope this can help you - otherwise please ellaborate what you are trying to achieve and we will have a look at what can be done.

BR Nicolai

 
Peter Leleulya
Reply

Thanks Nicolai, I will give it a try !

 

You must be logged in to post in the forum