Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have an SPLongOperation that occasionally fails to redirect the user to a new page when the operation completes. I'm not sure what circumstances cause the problem, since I don't yet have a reliable way to reproduce it. Here is the code I am using:

using (SPLongOperation createOp = new SPLongOperation(this.Page)) {
   createOp.LeadingHTML = "Title";
   createOp.Begin();

   string error = DoSomeLongRunningStuff();

   if (String.IsNullOrEmpty(error)) {
      createOp.End(this.Web.Url);
   } else {
      createOp.End(SPUtility.ErrorPage, SPRedirectFlags.RelativeToLayoutsPage, HttpContext.Current, "ErrorText=" + error);
   }
}

When the problem occurs, it's clear that the long operation has completed successfully (i.e. DoSomeLongRunningStuff() returns a result), but the user is never redirected to a new page. Does anyone know of any reason why redirection might fail?

share|improve this question

1 Answer 1

You say it fails to redirect? Does that mean you get an error, or the loading screen just displays forever?

I would suggest checking if the application pool recycles.

Then check it using the standard long operation html

using (SPLongOperation createOp = new SPLongOperation(this.Page)) {
    createOp.LeadingHTML = this.GetLocString("WrkTask_PreGears");
    createOp.TrailingHTML = string.Format(this.GetLocString("WrkTask_PostGears"), Request.Url);
    createOp.Begin();

    string error = DoSomeLongRunningStuff();

    if (String.IsNullOrEmpty(error)) {
        createOp.End(this.Web.Url);
    } else {
        createOp.End(SPUtility.ErrorPage, SPRedirectFlags.RelativeToLayoutsPage, HttpContext.Current, "ErrorText=" + error);
    }
}

protected string GetLocString(string strName) {
    return (string)System.Web.HttpContext.GetGlobalResourceObject("dlc", strName);
}

Finally, it might be that the garbage collector is destroying some references somewhere, try making either the return value or the method related to the member class. See this source file, how the this.CurrentJob inside the long operation is a member class variable.

http://spc2.codeplex.com/SourceControl/changeset/view/942#46626

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.