Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6899439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:25:19+00:00 2026-05-27T07:25:19+00:00

I am trying to run SharePoint’s SPSiteDataQuery for all web in the Site Collection

  • 0

I am trying to run SharePoint’s SPSiteDataQuery for all web in the Site Collection for a collection of lists. The average time to get data from all sites for one list [spWeb.GetSiteData(dataQuery)] is anywhere between 1 to 20 seconds. The list collection can virtually have any number of lists in it.

I have implemented the threading logic as below. But I get different amount of records on every call. I am not much experienced with multi-threading architecture. What is going on, and is it worth my thinking about a better threading architecture?

private static Dictionary<string,string> _workTypes = new Dictionary<string, string>();
private static Dictionary<string,string> _workspaces = new Dictionary<string, string>();
private static List<string> _processedMyWorkItems = new List<string>(); 
private static readonly object Locker = new object();

var threads = new List<Thread>();
var processedMyWorkData = new Dictionary<string, List<XElement>>();

foreach (string selectedList in selectedLists.Distinct().OrderBy(l => l))
{
    string theSelectedList = selectedList;

    string listIds = string.Empty;

    foreach (string listId in GetListIdsFromDb(selectedList, spWeb, archivedWebs)
        .Where(listId => !selectedListIds.Contains(listId)))
    {
        selectedListIds.Add(listId);
        listIds += string.Format(@"<List ID='{0}'/>", listId);
    }

    if (string.IsNullOrEmpty(listIds)) continue;

    dataQuery.Lists = string.Format("<Lists MaxListLimit='0'>{0}</Lists>", listIds);

    var thread = new Thread(() =>
    {
        List<XElement> processedMyWork = ProcessMyWork(selectedFields, spSite, spWeb, dataQuery, fieldTypes);

        lock (Locker)
        {
            processedMyWorkData.Add(theSelectedList, processedMyWork);
        }
    }) { Name = theSelectedList };

    threads.Add(thread);
    thread.Start();
}

bool done = false;

while (!done)
{
    Thread.Sleep(500);

    bool noThreadIsAlive = true;
    var threadsCompleted = new List<Thread>();

    foreach (var thread in threads)
    {
        if (thread.IsAlive)
        {
            noThreadIsAlive = false;
        }
        else
        {
            threadsCompleted.Add(thread);
        }
    }

    foreach (var thread in threadsCompleted)
    {
        threads.Remove(thread);

        string key = thread.Name;
        foreach (var xElement in processedMyWorkData[key])
        {
            result.Element("MyWork").Add(xElement);
        }

        lock (Locker)
        {
            processedMyWorkData.Remove(key);
        }
    }

    done = noThreadIsAlive;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:25:19+00:00Added an answer on May 27, 2026 at 7:25 am

    Just looking at the synchronization issue, you need to be using the WaitAll() rather than looping around WaitOne() or polling on the IsAlive property.
    To set it up, you’ll need an event for each thread then add them to an array in the main thread that will uses it to wait on all the events at once.
    Note that there is a maximum of 64 events that can be monitored by WaitAll().

    http://msdn.microsoft.com/en-us/library/3dasc8as(v=vs.80).aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the internal status of all sharepoint workflows. Is there anyway
I am trying to copy an SPListItem (with file) from one site collection to
Trying to run my program through java web start. I get the following exception
I am trying to call a Sharepoint Web Service via WCF from inside a
I am trying run a program from a qmake .pro file which modifies the
When trying to run an Eclipse Dynamic Web Project under a Tomcat setup using
I'm trying to write an HttpModule to run on our SharePoint farm - essentially
I'm trying to insert a bunch of data into a SharePoint list. The List
I'm trying to pop a window up, from inside a procedure running in SharePoint.
I try to add a new web application in sharepoint central administration and get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.