是否可以在 Web 部件中使用多线程访问 SharePoint 2010 列表?

发布于 2024-10-03 21:28:37 字数 1094 浏览 5 评论 0原文

我正在尝试从自定义 Web 部件访问 SharePoint 2010 列表中的项目。使用线程时,List.ItemCount 属性是准确的,但项目集合为空。有没有人找到解决这个问题的方法?我访问列表的代码如下:

    protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
    {
        Thread wThread = new Thread(new ThreadStart(WriteW));
        //only showing one thread for simplicity
        wThread.Start();
        Thread.Sleep(500);

        while (threadcount > 0)
        {
            Thread.Sleep(400);
        }
        lblGreeting.RenderControl(writer);

    }

    public void WriteW()
    {
        lock (lockobject)
        {
            threadcount++;
        }
        SPSite spsConflictSite = new SPSite("http://myserver/mysite");
        SPWeb spwConflictWeb = spsConflictSite.OpenWeb();
        SPList splConflictList = spwConflictWeb.Lists["Thread Tester List"];
        DataTable myTable = splConflictList.Items.GetDataTable();
            lblGreeting.Text += " " + myTable.Rows[0]["Title"].ToString();
            spsConflictSite.Dispose();
        lock (lockobject)
        {
            threadcount--;
        }
    }

I am trying to access the items in a SharePoint 2010 list from a custom webpart. When using threading, the List.ItemCount property is accurate, but the item collection is empty. Has anyone found a way around this? My code for accessing the list is below:

    protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
    {
        Thread wThread = new Thread(new ThreadStart(WriteW));
        //only showing one thread for simplicity
        wThread.Start();
        Thread.Sleep(500);

        while (threadcount > 0)
        {
            Thread.Sleep(400);
        }
        lblGreeting.RenderControl(writer);

    }

    public void WriteW()
    {
        lock (lockobject)
        {
            threadcount++;
        }
        SPSite spsConflictSite = new SPSite("http://myserver/mysite");
        SPWeb spwConflictWeb = spsConflictSite.OpenWeb();
        SPList splConflictList = spwConflictWeb.Lists["Thread Tester List"];
        DataTable myTable = splConflictList.Items.GetDataTable();
            lblGreeting.Text += " " + myTable.Rows[0]["Title"].ToString();
            spsConflictSite.Dispose();
        lock (lockobject)
        {
            threadcount--;
        }
    }

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

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

发布评论

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

评论(1

山人契 2024-10-10 21:28:37

我认为在线程中使用 Dispose 可能是一个问题。尝试将 SPSite 调用包装在 using 语句中,以使 .net 重新获得对处置的一些控制权。我已经在 SP2010 中使用了多线程,但它是一头猪,并且有很多“计划外的功能”。

我当时确实与微软打了一个支持电话,他们的回答是这应该是可能的,但不受支持。

I think using Dispose in the thread could be an issue. Try wrapping the SPSite call in a using statement to give .net back some control over the disposal. I have had multithreading in SP2010 working but it was a pig and had a lot of "unplanned features".

I did have a support call with Microsoft open at the time and their answer was that it should be possible but wasn't supported.

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