views:

568

answers:

5

I have used the Long Running Operation capability within the Publishing Infrastructure within MOSS (SharePoint) in the past, and am curious if anyone knows if this is a supported technique for having custom long running operations within SharePoint.

When using this technique, you inherit from Microsoft.SharePoint.Publishing.Internal.LongRunningOperationJob which seems to indicate that it is not supported for custom use, but I seem to recall (maybe I dreamt?) that long running processes was a marketed feature of MOSS.

Any ideas?

A: 

This is the site I used to get me started:

http://geek.hubkey.com/2007/11/provide-status-updates-for-long-running.html

Provides a decent code example as well.

theG
Thanks for sharing. I've seen this one or one like it before.
Kirk Liemohn
+1  A: 

Good question Kirk! I have recently also experienced the need to implement long running jobs in SharePoint. But the LongRunningOperationJob was not an option as it also needed to work with a plain WSS 3.0 deployment. I simply ended up spawning a new thread from the Web request and redirecting to an ASPX page with an AJAX enabled progress bar updating itself every other second. It works perfectly well and can run as long as needed. Only downside is that an IISRESET will kill it for good. Another possibility could be to implement long running jobs using a custom SharePoint Timer Job.

Lars Fastrup
Thanks for sharing your solution, Lars. I'll probably stick with the Publishing Infrastructure option since it is the lowest cost option available to us.
Kirk Liemohn
+2  A: 

SharePoint Timer Jobs are described in MSDN Journal April edition http://msdn.microsoft.com/en-us/magazine/dd569748.aspx

salgo60
Great article - just what I have been looking for :-)
Lars Fastrup
Good article (I had heard about it from a co-worker but not read it until now so thanks for sharing). It may be a little overkill for our budget, though.
Kirk Liemohn
+1  A: 

SPLongOperation is a very simple way to do a long running operation. Much simpler than the Publishing.LongRunningOperationJob and uses the same infrastructure.

JD
A: 

Ever woundered how microsoft create the nice longrunning process windows works in SharePoint 2007?

SPLongOperation is the class to use. It has 2 important methods

Begin and End;

All your code that runs for a long time is placed between begin and end.

Below is a sample class.

It is almost to simple and just works :-)

using System;
using System.Web;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
namespace CreateLongOperation
{
public class LongRun : System.Web.UI.Page
{
  protected Button buttonOk;

  protected void Page_Load(object sender, EventArgs e)
  {
     buttonOk.Click += new EventHandler(buttonOk_Click);
  }

  void buttonOk_Click(object sender, EventArgs e)
  {
     SPLongOperation operation = new SPLongOperation(this.Page);

     operation.Begin();

     // do long operation code here...
     System.Threading.Thread.Sleep(6000);

     operation.End("http://sps/_layouts/Mynewpage.aspx");
  }
 }
}
David Scott