HttpContext.Current is null when in method called from PageAsyncTask

z45

New Member
I have a scenario where i have a page which opens a dialog on click of a button, in the opened dialog form on button click i can read a list of data from a selected .txt file and build a query and add the data to some database tables. Since there could be large amount of data this process can take large time because of this the user would not be able to work on the application until the upload completes. Hence to make the upload process Asynk i am using the PageAsyncTask. Below is the code sample, but in the method called in the PageAsyncTask the HttpContext.Current is null hence i am not able to use session handling. Please any guidance on this why would this be null and how can i use the session in this case\[code\] protected void BtnUpload_click(object sender, EventArgs e) { PageAsyncTask asyncTask1 = new PageAsyncTask(OnBegin, OnEnd, OnTimeout, SessionManager.UserData, true); Page.RegisterAsyncTask(asyncTask1); Page.ExecuteRegisteredAsyncTasks(); }public IAsyncResult OnBegin(object sender, EventArgs e, AsyncCallback cb, object extraData) { _taskprogress = "AsyncTask started at: " + DateTime.Now + ". "; uData = http://stackoverflow.com/questions/13843744/extraData as UserData; _dlgt = new AsyncTaskDelegate(BeginInvokeUpload); IAsyncResult result = _dlgt.BeginInvoke(cb, extraData); return result; }private void BeginInvokeUpload() { string selectedFileName = string.Empty; string returnValuePage = string.Empty; User teller = new User(); SessionManager.UserData = uData; } private void BeginInvokeUpload() { string selectedFileName = string.Empty; string returnValuePage = string.Empty; User teller = new User(); SessionManager.UserData = uData; }public class SessionManager {public static UserData UserData { get { UserData userData = null; if (HttpContext.Current.Session["UserData"] != null) { userData = http://stackoverflow.com/questions/13843744/HttpContext.Current.Session["UserData"] as UserData; } return userData; } set { HttpContext.Current.Session["UserData"]=value; } }}\[/code\]
 
Back
Top