2

I just discovered the SPLongOperation class. It is a thing of beauty. I was expecting to have to implement a "job handler" static class, fire off my long-running process in a separate background thread, check in on it via a timer with polling, etc. Until I found this example.

http://peterheibrink.wordpress.com/2009/09/07/splongoperation/

Can someone point me to, or shed some light on how exactly the SPLongOperation class is able to do so much for me with so few lines of code?

UPDATE: I found a bit more information here:

http://dotnetfollower.com/wordpress/2011/08/sharepoint-how-to-use-splongoperation/

Specifically: Please also note that SPLongOperation keeps connection between client and server alive and the Response stream open.

Looks like I'll have to do it the old-fashioned way after all... I thought SPLongOperation had built-in polling of some kind.

2
  • Maybe you should ask on stackoverflow directly, with the ASP.Net tag
    – Steve B
    Commented Nov 28, 2012 at 16:14
  • Will do, I'm also interested in the mechanics of how it works though, I'll update the question.
    – mikey
    Commented Nov 28, 2012 at 16:24

2 Answers 2

2

SPLongOperation delegates the page to another process, redirects to the nice lala land waiting page, then when it's ready it transfers you to the results page.

Simples.

1
  • 1
    It appears it doesn't work for me because it keeps the response stream open. My issue is my process is long enough that there are proxy servers between the server and the client whose timeouts are getting triggered, severing the response stream. The result is that the "end" redirect never happens. Do you know of a clean alternative? I am looking at an updatepanel / backgroundworker combo right now.. I'm not sure how my SPContext.Current will work in a backgroundworker though.
    – mikey
    Commented Nov 28, 2012 at 17:40
1

Depending on what you are trying to accomplish there are advantages to using the SPLongOperation.

I recently implemented a solution using the SPLongOperation when I wanted the user to wait for the action to complete (which was create a web under the site collection a specific way) and then be redirected to that new web. You can take advantage of the SPLongOperation.EndScript() to do something like this. Another advantage of this is it will automatically create a nice visual that the users are already used to seeing in SharePoint while the operation is being performed.

If you use a SharePoint custom workflow to do whatever long operation you are trying to accomplish it will take advantage of the timer jobs built into SharePoint workflows. You can even create an a completed event receiver to handle the completed event of the workflow.

For more info check out: http://msdn.microsoft.com/en-us/magazine/ee335710.aspx

It really depends on what you are trying to accomplish.

2
  • I have a visual web part with a button, which when clicked can take upwards of 30 seconds to give a response. I believe I've optimized the code that gets fired on button click to the extent that I can (using batch updates, disabling event receivers, etc). I managed to speed it up quite a bit but certain clients (ahem IE7) are timing out waiting for the response.
    – mikey
    Commented Nov 28, 2012 at 17:44
  • If that's the case and you are just using a button and posting back to the server when the button is clicked, I would use the SPLongOperation. It will display the nice animation and allow you to execute javascript or redirect once the operation is complete.
    – jmshapland
    Commented Nov 30, 2012 at 1:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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