Async Task Session is null.

Answered
0
0

Hi,

I recently converted my WinForms application to Wisej and it is awesome!

But I am having difficulty running my application deployed on IIS.  It runs fine locally in visually studio.

It appears when I am running live on IIS the Application Session is null in certain parts of the program.

I am pretty sure it has to do with Async Tasks but I cannot pinpoint it down.  I know it is difficult to explain with out reviewing my source code.

But here is basically what is happening:

event is triggered on a Wisej.UserContol:

public async void pnlTransaction_Reconfigure(object sender, EventArgs e)
{
await ShowTransactionAsync();
}

public async Task ShowTransactionAsync()
{
Application.ShowLoader = true;
Application.Update(this);
var config = Application.Session.Config;   <– this returns null
await RefreshTransactionDetailsAsync(config);
Application.ShowLoader = false;
Application.Update(this);
}

Now this is not my actual source code but similar to what I am doing.  On my local machine this code runs fine but deployed on IIS I get a null exception.  So I cannot reproduce the error.

I am looking for any suggestions that will help.  I have tried Application.RunInContext, Application.StartTask and inserting Application.Update but it doesn’t seem to resolve the issue.  I know I am missing something here and I am new to Async and Wisej programming so any help would be appreciated.

Thanks,

Devin

 

 

 

 

  • You must to post comments
Great Answer
0
0

Hi Devin,

Attached is a sample to demonstrate how you could use async tasks with Wisej.NET.

You’ll have to use Application.StartTask with whatever method you’d want to use for it to be ran on the “Current context”.

HTH,
Alaa

  • You must to post comments
0
0

Hi Alaa,

Thank you for your answer and example.  I am not sure this is the issue I am having, I think the problem I am having is in static class functions in my library are not thread safe.  Anyways could you verify something for me, I want to make sure how I am handling Session variables is thread safe.

I made a static class for my Application.Session look ups like this.

public static class AppSession
{

public static IConfig Config { get { return (IConfig)Application.Session.Config; } set { Application.Session.Config = values; } }

public static IUser User { get { return (IUser)Application.Session.User;} set {Application.Session.User = value; } }

}

then in my code event I would

private async void myForm_DisplayUser(object sender, EventArgs e)
{
var user = AppSession.User;
lblUserName.Text = User.Username;
Application.Update(this);
}

Would putting your Application Session variables in a static class a bad idea?  I thought I saw in an example this was how you could change static variables to session variables.

Thanks,

Devin

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.