Wisej.Web.Application.Session is null in another thread.

Welcome to Wisej Support.
Questions, suggestions and plain old bugs - are all welcome here!
0
0

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

  • Tung Ngo
    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)
  • Luca (ITG)
    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.
  • You must to post comments
0
0

Hi Tung,

The session is always null in a new thread unless Wisej has a chance to restore it. See this thread: http://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: http://wisej.com/docs/html/BackgroundTasks.htm.

Best,

Luca

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Attachment
File Name Size
There are currently no files uploaded.
Maximum number of files 5, maximum file size 3.9MB.
Supported file formats: zip pdf gif jpg bmp png cs vb theme json