Hello,
When i access Wisej.Web.Application.Session from another thread, it is always null. Please advise the solution.
Thanks
Here is my code:
Public Sub Main()
Wisej.Web.Application.Session.SessionVar = “ABC”
ReadSessionVarAsync()
Dim window As New Window1()
window.Show()End Sub
Async Sub ReadSessionVarAsync()
Dim sessionVar As String = String.Empty
Await Threading.Tasks.Task.Run(Sub()‘Wisej.Web.Application.Session always nothing in this thread.
sessionVar = Wisej.Web.Application.Session(“SessionVar”)End Sub)
End Sub
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
Please login first to submit.