Also, in SharePoint 2010 (and maybe before, for all I know) there's the SPStatefulLongOperation
class. It's not very well documented, but here's an example of how I might be using it.
SPStatefulLongOperation.Begin(
"Applying theme to sites.",
"<span id='trailingSpan'></span>",
(op) =>
{
op.Run((state) =>
{
foreach (SPWeb web in site.AllWebs)
{
state.Status =
"<script type='text/javascript'>" +
"document.all.item('trailingSpan').innerText = '" +
web.Title +
"';" +
"</script>";
selectedTheme.ApplyTo(web, true);
}
});
op.End("ManageFeatures.aspx?Scope=Site");
});
This works very similarly to the custom method above: every second, the value of state.Status
is written to the Response
(via HttpContext.Current
) and flushed. Thus you want to be sending JavaScript updating your status element, rather than sending the current status. It's less efficient in that it sends the state even when it hasn't changed, but using the ootb code is a lot cleaner.