微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当我尝试访问默认日历文件夹时,Outlook 插件卡住了

如何解决当我尝试访问默认日历文件夹时,Outlook 插件卡住了

我已经实现了一个执行同步过程的 Outlook 插件在这里,我使用 Redemption 来访问用户认日历文件夹。但是当尝试访问认日历文件夹时,用户的其中一个 Outlook 卡住了。他们使用的是内部交换服务器,并且他们的认日历文件夹中只有大约 50 个项目。我为此使用了后台线程。

这是我在主 ADXForm 中使用后台线程的方法

   private void syncWorker_DoWork(object sender,System.ComponentModel.DoWorkEventArgs e)
    {
        try
        {                
            Helper.DoSyncInBackground();               
        }
        catch (System.Exception ex)
        {
            Debug.DebugMessage(2,$"Error in adxFormMainPanel (syncWorker_DoWork) {ex.Message}");
        }
    }

这是我初始化 Redemption 的方法

 public static void DoSyncInBackground()
    {
        try
        {
            var redemptionCode = new RedemptionCode();
            redemptionCode.InitialiseRedemption(Globals.MapiObject);
            DoSync(redemptionCode);
        }
        catch (Exception ex)
        {
            Debug.DebugMessage(2,$"Error in Helper (DoSyncInBackground) {ex.Message}");
        }
    }

      public bool InitialiseRedemption(object MAPIObject)
    {
        try
        {
            Debug.DebugMessage(5,"starts Intialize Redemption");
            string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            RedemptionLoader_DllLocation64Bit_FilePath = path + "\\Redemption64.dll";

            RedemptionLoader_DllLocation32Bit_FilePath = path + "\\Redemption.dll";

            Debug.DebugMessage(4,"Redemption FilePath 32:- " + RedemptionLoader_DllLocation32Bit_FilePath);

            Debug.DebugMessage(4,"Redemption FilePath 64:- " + RedemptionLoader_DllLocation64Bit_FilePath);

            if (File.Exists(RedemptionLoader_DllLocation32Bit_FilePath) && File.Exists(RedemptionLoader_DllLocation64Bit_FilePath))
            {
                RedemptionLoader.DllLocation32Bit = RedemptionLoader_DllLocation32Bit_FilePath;
                RedemptionLoader.DllLocation64Bit = RedemptionLoader_DllLocation64Bit_FilePath;
            }
            else
            {
                Debug.DebugMessage(1,AllMessages.MsgRedemptionDllNotFound);
                return false;
            }

            rSession = RedemptionLoader.new_RDOSession();
            Debug.DebugMessage(4,"InitialiseRedemption : New RDO session Created");

            if (rSession != null)
            {
                //We need a MAPIOBject from Outlook when we initialise
                rSession.MAPIOBJECT = MAPIObject;
                bool loggedOn = rSession.LoggedOn;
                string rMode = rSession.ExchangeConnectionMode.ToString();
                RDOAddressEntry currentUser = rSession.CurrentUser;
                OutlookUserName = currentUser.Name;

                if (currentUser.Type == "EX")
                {
                    CurrentUserEmail = currentUser.SMTPAddress;
                }
                else
                {
                    CurrentUserEmail = currentUser.Address;
                }
                if (string.IsNullOrWhiteSpace(CurrentUserEmail))
                {
                    CurrentUserEmail = currentUser.Address;
                    //currentUserEmail = CCGlobals.OLCurrentUserEmail; 
                }

                if (currentUser != null) Marshal.ReleaseComObject(currentUser);

            }
            //Occassionally we force Garbage Collection
            GC.Collect();
            return true;
        }

        catch (System.Exception ex)
        {
            Debug.DebugMessage(2,$"Error in InitialiseRedemption (RedemptionCode) {ex.Message}");
        }
        return false;
    }

同步如下

  private static void DoSync(RedemptionCode redemptionCode)
    {           
        List<string> updatedAppointments;
        List<string[]> plannedItemList = new List<string[]>();
        List<string[]> pendingItemList = new List<string[]>();
        try
        {
            
                pendingItemList = GetPendindItemList();
                plannedItemList = GetplannedItemList();
                var combinationOfPendingAndplannedItems = GetPendingAndplannedListWrapper(pendingItemList,plannedItemList);
                if (combinationOfPendingAndplannedItems != null && Globals.UserSettings.SyncSettings == (int)SyncType.calendarandTasks)
                {                        
                    updatedAppointments = redemptionCode.UpdateOrDeleteExistingAppointments(combinationOfPendingAndplannedItem
                }                   
            }
        }
        catch (Exception ex)
        {
            Debug.DebugMessage(2,$"Error in Helper (DoSync) {ex.Message}");
        }
    }

 internal List<string> UpdateOrDeleteExistingAppointments(List<ItemWrapper> combinationOfPendingAndplannedItems)
    {
        RDOFolder calendarFolder = null;
        RDOItems calendarFolderItems = null;
        RDOAppointmentItem appointment = null;
        List<string> updatedAppointmentIdList = new List<string>();
        List<string> appointmentIdListTobedeleted = new List<string>();
        try
        {
            Debug.DebugMessage(3,"RedemptionCode : UpdateOrDeleteExistingAppointments() : Started");
            calendarFolder = rSession.GetDefaultFolder(rdoDefaultFolders.olFolderCalendar);
            if (calendarFolder != null)
            {
                calendarFolderItems = calendarFolder.Items;
                if (calendarFolderItems != null)
                {
                    for (int i = 1; i <= calendarFolderItems.Count; i++)
                    {
                        try
                        {
                            appointment = calendarFolderItems[i] as RDOAppointmentItem;
                            if (appointment != null)
                            {
                                var updateOrDeleteItems = UpdateOrReturnAppointemntsTobedeleted(ref appointment,combinationOfPendingAndplannedItems);
                                if (updateOrDeleteItems != null)
                                {
                                    if (!string.IsNullOrWhiteSpace(updateOrDeleteItems.updatedItem))
                                    {
                                        updatedAppointmentIdList.Add(updateOrDeleteItems.updatedItem);
                                    }
                                    if (!string.IsNullOrWhiteSpace(updateOrDeleteItems.itemTobedeleted))
                                    {
                                        appointmentIdListTobedeleted.Add(updateOrDeleteItems.itemTobedeleted);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.DebugMessage(2,$"Error in UpdateOrDeleteExistingAppointments (RedemptionCode)[For loop] {ex.Message}");
                        }
                        finally
                        {
                            if (appointment != null) Marshal.ReleaseComObject(appointment);
                        }
                    }
                    if (appointmentIdListTobedeleted != null && appointmentIdListTobedeleted.Count > 0)
                    {
                        DeleteMarkedAsCompletedAppointments(appointmentIdListTobedeleted);
                    }
                }
            }
            Debug.DebugMessage(3,"RedemptionCode : UpdateOrDeleteExistingAppointments() : Completed");
            return updatedAppointmentIdList;
        }
        catch (Exception ex)
        {
            Debug.DebugMessage(2,$"Error in UpdateOrDeleteExistingAppointments (RedemptionCode) {ex.Message}"); ;
            return updatedAppointmentIdList;
        }
        finally
        {
            if (calendarFolderItems != null) Marshal.ReleaseComObject(calendarFolderItems);
            if (calendarFolder != null) Marshal.ReleaseComObject(calendarFolder);
        }
    }

用户的 Outlook 在尝试获取认日历文件夹时卡住

 calendarFolder = rSession.GetDefaultFolder(rdoDefaultFolders.olFolderCalendar);

谢谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?