Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1062439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:37:35+00:00 2026-05-16T18:37:35+00:00

I have a aspx page in which i create reports and charts on the

  • 0

I have a aspx page in which i create reports and charts on the fly. Creation of these charts and reports takes a lot of time because of which a blank screen is shown to the user until the creation completes.

To solve this problem I am trying to trigger report generation in a separate thread on page load and when the reportgeneration completes i am trying to set a session variable to indicate completion. I have a AJAX timer which keeps checking for this flag.

protected void Page_Load( object sender, EventArgs e )
{
    if ( !IsPostBack )
    {
        ThreadPool.QueueUserWorkItem( new WaitCallback( DoLongRunningProcess ) );
    }
}
public void GenerateReport( object state )
{
    ///generate report
    Session[ "done" ] = true;
}

The problem is that Session is null(Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration.) when i am trying set the completion flag.

Can you guys tell me how to workaround this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:37:36+00:00Added an answer on May 16, 2026 at 6:37 pm

    The problem is that in a new thread, HttpContext.Current (and Session in it) is not available.

    One solution is to create an instance that you pout in Session and also sens to worker thread as a parameter:

    1. Declare a Status class:

      public class MyStatus {
      public Exception Exception { get; set; }
      public bool IsDone { get; set; }
      }

    2. Before start processing, put an instance in the Session that your ajax callback can check. Also gives object as argument to worker thread.

      protected void Page_Load( object sender, EventArgs e )
      {
      if ( !IsPostBack )
      {
      MyStatus myStatus = new MyStatus();
      Session[“MyStatus”] = myStatus;
      ThreadPool.QueueUserWorkItem(DoLongRunningProcess , myStatus );
      }
      }

    3. In your worker thread, set the flag that processing is done.

      public void GenerateReport( object state )
      {
      MyStatus myStatus = state as MyState;

      ///generate report
      myStatus.IsDone = true;
      

      }

    4. In your ajax callback, check status. If you are done, also remove status from Session.

      MyStatus myStatus = Session[“MyStatus”] as MyState;
      if (myStatus.IsDone)
      {
      // do something.

      // cleanup.
      Session.Remove("MyStatus");
      

      }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a moderately complex web page. This is not something
I would like to create a compiled query which uses reusable where predicates. An
I have a JSON data store used for a combobox selection which is working
I have an XSLT transform I am using to process an XML file, inserting
In an earlier post I asked about how to create short form for my
I have a DotNetNuke website that by default people use anonymously. When they want
In my current application I want to implement ASP.Net localization with global resources. I
So today I started learning ASP.NET. Unfortunately I haven't found any good tutorials online,
I'm just starting out learning ASP.NET. From what I understand, ASP.NET differs from old

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.