Sharepoint 2010 spstatefullong操作的使用

Sharepoint 2010 spstatefullong操作的使用,sharepoint-2010,Sharepoint 2010,有人能给我举一个使用SPSTATEFULLONG操作的例子吗?这是一个我刚刚使用过的代码示例。它将ThmxTheme(selectedTheme)应用于SPSite(site)中的所有spweb) SPStatefulLongOperation.Begin( “将主题应用于网站。”, "", (op)=> { 操作运行((操作状态)=> { for(int i=0;i

有人能给我举一个使用SPSTATEFULLONG操作的例子吗?这是一个我刚刚使用过的代码示例。它将
ThmxTheme
selectedTheme
)应用于
SPSite
site
)中的所有
spweb

SPStatefulLongOperation.Begin(
“将主题应用于网站。”,
"",
(op)=>
{
操作运行((操作状态)=>
{
for(int i=0;i
请注意,
opState.State
的当前值每秒都会附加到客户端的HTML中(通过
HttpContext.current.Response.Write
Flush
)。因此,您不想直接发送任何状态消息;您希望发送一些JavaScript来更新页面上现有的状态元素。(此处为
trailingSpan
元素。)

SPStatefulLongOperation.Begin(
    "Applying theme to sites.",
    "<span id='trailingSpan'></span>",
    (op) =>
    {
        op.Run((opState) =>
        {
            for (int i = 0; i < site.AllWebs.Count; i++)
            {
                // Update status.
                opState.Status = String.Format(
                    "<script type='text/javascript'>document.all.item('trailingSpan').innerText = '{0} ({1} of {2})';</script>",
                    site.AllWebs[i].Title,
                    i + 1,
                    site.AllWebs.Count);

                // Set the theme.
                selectedTheme.ApplyTo(site.AllWebs[i], true);
            }
    });

    op.End(System.Web.HttpContext.Current.Request.UrlReferrer.ToString());
});