You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wisej.Web.Application.Session is null in another thread. #619
Please note that Sub ReadSessionVarAsync is a simplified example for illustration only.
In reality, this sub is in a third party dll, which I have no access to it. So there is no change for me to use Wisej.Web.Application.StartTask.
Besides, Async Sub ReadSessionVarAsync() is used widely in Business Object layer, which has no knowledge about User Interface layer. (Wisej/Winform/Mobile)
I read this comment I posted the StartTask suggestion. The only way to restore the session is to have a reference to the session. The session is referenced in all Wisej components or in a cookie or in the URL – otherwise there is no way for a thread to know about a specific session in any web system. You can also use Application.RestoreSession(HttpContext), in which case you don’t need a Wisej component but you need the http context to read the session id from the cookie or the URL.
Activity
itg-assistant commentedon Jun 12, 2026
Tung Ngo answered 2017-02-08 08:47:16 UTC
Please note that Sub ReadSessionVarAsync is a simplified example for illustration only.
In reality, this sub is in a third party dll, which I have no access to it. So there is no change for me to use Wisej.Web.Application.StartTask.
Besides, Async Sub ReadSessionVarAsync() is used widely in Business Object layer, which has no knowledge about User Interface layer. (Wisej/Winform/Mobile)
itg-assistant commentedon Jun 12, 2026
Luca answered 2017-02-08 15:58:26 UTC
Hi Tung,
The session is always null in a new thread unless Wisej has a chance to restore it. See this thread: https://wisej.com/support/question/updating-ui-elements-from-other-threads
You can restore the session on any thread in several ways:
1- Use Application.StartTask(()=>{ ...code in context...});
2-Use Application.RunInContext(this, ()=>{... code in context..}); You need "this" to be a component (control, page, window, etc.)
The best way is no. 1. See the BackgroundTasks example in the examples section and see the background tasks help section: https://docs.wisej.com/docs/concepts/background-tasks.
Best,
Luca
itg-assistant commentedon Jun 12, 2026
Luca answered 2017-02-08 17:48:21 UTC
I read this comment I posted the StartTask suggestion. The only way to restore the session is to have a reference to the session. The session is referenced in all Wisej components or in a cookie or in the URL – otherwise there is no way for a thread to know about a specific session in any web system. You can also use Application.RestoreSession(HttpContext), in which case you don’t need a Wisej component but you need the http context to read the session id from the cookie or the URL.