线程遍历List所有数据行

 

  protected void btnTAd_Click(object sender, EventArgs e)
        {
            if (ThreadSite == null)
            {
                ThreadSite = SPContext.Current.Site;
            }
            Thread threads = new Thread(new ParameterizedThreadStart(SyncTeacherAD));
            threads.Name = "Thread22";
            threads.Priority = ThreadPriority.Highest;
            threads.Start(GZQHUtilities.SPUtilities.Webs.DatabaseWebUrl);
        }
 public void SyncTeacherAD(object obj)
        {
            try
            {
                using (SPWeb web = ThreadSite.OpenWeb(obj.ToString()))
                {
                    bool unsfaleupdate = web.AllowUnsafeUpdates;
                    web.AllowUnsafeUpdates = true;
                    SPList list = gzqhUtil.Lists.GetListFromWeb(web, lstTeacher);
                    SPQuery query = new SPQuery();
                    query.Query = "<Where><And><Gt><FieldRef Name='ID'/><Value Type='Integer'>8445</Value></Gt><IsNotNull><FieldRef Name='" + fldPassword + "'/></IsNotNull></And></Where>";
                    query.RowLimit = 50;
                    query.ViewFields = "<FieldRef Name='" + fldAccountID + "'/><FieldRef Name='" + fldPassword + "'/><FieldRef Name='"+fldName+"'/>";
                    do
                    {
                        SPListItemCollection listItems = list.GetItems(query);
                        foreach (SPListItem listItem in listItems)
                        {
                            string userAccount = listItem[fldAccountID]+"";
                            string password = string.Empty;
                            try
                            {
                                  password = gzqhUtil.CryptoHelper.Decrypt(listItem[fldPassword]+"", GZQHUtilities.SPUtilities.CryptoHelper.CRYPTO_KEY);
                            }
                            catch
                            {
                                continue;
                            }
                            LoginModule._loginModule.AddUserToAD(ThreadSite, userAccount, listItem[fldName]+"", password, People.Teacher);
                        }
                        query.ListItemCollectionPosition = listItems.ListItemCollectionPosition;

                    }
                    while (query.ListItemCollectionPosition != null);
                    web.AllowUnsafeUpdates = unsfaleupdate;
                }
            }
            catch (Exception ex)
            {
                Exceptions.WriteEvent("SyncTeacherAD", ex.Message, EventLogEntryType.Error);
            }
           
        }

 

  protected void btnTAd_Click(object sender, EventArgs e)
        {
            if (ThreadSite == null)
            {
                ThreadSite = SPContext.Current.Site;
            }
            Thread threads = new Thread(new ParameterizedThreadStart(SyncTeacherAD));
            threads.Name = "Thread22";
            threads.Priority = ThreadPriority.Highest;
            threads.Start(GZQHUtilities.SPUtilities.Webs.DatabaseWebUrl);
        }

posted on 2015-11-16 11:30  !无名之辈  阅读(209)  评论(0)    收藏  举报