سؤال

أكتب جهاز استقبال حدث في مكتبة مستندات لإنشاء قائمة جديدة من ملف Excel الذي تم تحميله. يتم تشغيله على حدث مستند () وثيق ().

قبل استدعاء طريقة لإضافة عناصر جديدة إلى قائمة أحتاج إلى مسح العناصر القديمة، حاولت في البداية أن هذا بالطريقة التقليدية (التكرار في ترتيب تنازلي وحذف جميع السجلات) والآن مع processbatchdata giveacodicetagpre.

processbatachdata هو بعض ما أفضل ولكن لا يزال غير دقيق المشكلة هي أنه على الرغم من أن Debuggin بمجرد وصول عنصر التحكم إلى السطر var deleteBatch = site.OpenWeb().ProcessBatchData(BuildBatchDeleteCommand(site.OpenWeb().Lists[listName]));

يستغرق التحكم مرة أخرى إلى شاشة تحميل المستندات ومعظم الأوقات لا تصل إلى التعليمات البرمجية المتبقية، ولكن إذا كانت السجلات منخفضة حقا (<100) ثم تعالجها وتأخذ عنصر تحكم إلى السطر التالي (GuardaceticeTagcode) .

غير قادر على معرفة ما إذا كانت مشكلة موضوع الخيط، إذا نجحت هذا في وضع مؤشر ترابط الخاص بي للنوم لبعض الوقت حتى تنتهي المعالجات من عملها والتحكم إلى السطر التالي.

الوظيفة الكاملة تبدو وكأنها giveacodicetagpre.

المهوسون يرجى توجيهي إلى الاتجاه الصحيح. أنا حقا أقدر لك المساعدة والوقت.

vishal

هل كانت مفيدة؟

المحلول

This is probably not the root cause of your performance issues, but part of it. Your code is written in a quite inefficient way, opening webs to the right and left and looking for the list multiple times. Something like this does the same thing but more efficiently:

If your feature is web scoped:

    var web = properties.Feature.Parent as SPWeb;

if site scoped

    var site = properties.Feature.Parent as SPSite;
    if(site == null) return;
    var web = site.OpenWeb(properties.WebUrl);

and as MdMazzotti pointed out you would actually need to dispose the web in this scenario, I would use the using statement, replace the last line with this:

using(var web = site.OpenWeb(properties.WebUrl)){

and add an extra } at the end of the following :

    if(web == null || !web.Exists) return;

    var list = web.Lists[listName]
    if (list != null && list.Items.Count > 0)
    {
        var deleteBatch = web.ProcessBatchData(BuildBatchDeleteCommand(list));
    }

    InsertIntoList(ExcelRecords, list.Items);
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top