SPStatefulLongOperation的使用

发布于 2024-10-07 16:34:31 字数 54 浏览 0 评论 0原文

有人能给我一个使用 SPStatefulLongOperation 的例子吗?它的记录非常少。

Can someone give me an example of the use of SPStatefulLongOperation? It's very poorly documented.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人如初 2024-10-14 16:34:31

这是我刚刚使用的代码示例。它将 ThmxTheme (selectedTheme) 应用于 SPSite (site) 中的所有 SPWebs )。

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());
});

请注意,opState.State 的当前值每次都会附加到客户端的 HTML(通过 HttpContext.Current.Response.Write.Flush)第二。因此,您不想直接发送任何状态消息;您想要发送一些 JavaScript 来更新页面上现有的状态元素。 (此处为 trailingSpan 元素。)

Here's an example of code I've just used. It applies a ThmxTheme (selectedTheme) to all SPWebs in an SPSite (site).

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());
});

Note that the current value of opState.State is appended to the client's HTML (via HttpContext.Current.Response.Write and .Flush) every second. Thus you don't want to send any status message directly; you want to send some JavaScript that will update an existing status element on the page. (Here, the trailingSpan element.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文