Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 在Messageitem.send之后保留Outlookinstance_Vb.net_Outlook - Fatal编程技术网

Vb.net 在Messageitem.send之后保留Outlookinstance

Vb.net 在Messageitem.send之后保留Outlookinstance,vb.net,outlook,Vb.net,Outlook,我们的Outlook又出现了一个小问题, 如果没有Outlook实例正在运行,并且您在Vb.net中创建了约会项目,则只要display方法返回,outlookapplication就会终止,并从Taskmanager中消失,如果您尝试对该应用程序或项目进行任何进一步的调用,则会出现RPC Server not available异常 所以我的问题是:如果应用程序不是由用户启动的,如何防止它终止 其他信息: 只有在outlook关闭时尝试运行该程序时,才会出现这种情况,因此createAppoi

我们的Outlook又出现了一个小问题, 如果没有Outlook实例正在运行,并且您在Vb.net中创建了约会项目,则只要display方法返回,outlookapplication就会终止,并从Taskmanager中消失,如果您尝试对该应用程序或项目进行任何进一步的调用,则会出现RPC Server not available异常

所以我的问题是:如果应用程序不是由用户启动的,如何防止它终止

其他信息: 只有在outlook关闭时尝试运行该程序时,才会出现这种情况,因此createAppointment方法确实必须创建一个新任务。 如果应用程序已在运行,因此用户启动了一个实例,则没有问题

创建预约的代码:

  Public Function CreateAppointment(Appointment As InternalAppointmentClass) As Boolean
    Dim OutlookApp As Outlook.Application = CType(CreateObject("Outlook.Application"), Outlook.Application)
    Dim OlAppItem As Outlook.AppointmentItem = CType(OutlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem), Outlook.AppointmentItem)

    With OlAppItem
        .Start = Appointment .StartDate
        .Subject = Appointment .Subject
        .Location = Appointment .Location
        .End = Appointment .EndDate.addDays(1)
        .ReminderSet = False
        .AllDayEvent = True
        .BusyStatus = Outlook.OlBusyStatus.olFree
        .MeetingStatus = Outlook.OlMeetingStatus.olMeeting
        .ResponseRequested = True
        If IsNothing(.UserProperties.Find("DBID")) Then
            .UserProperties.Add("DBID", Outlook.OlUserPropertyType.olText, True, 1)
        End If
        .UserProperties("DBID").Value = getAppointmentChecksum(Appointment)
        'only need first element, because
        .Recipients.Add(CreateRecepientsAndCC(Appointment)(0))
        .Recipients.ResolveAll()
        .Display(True)
    End With

   'at this Point the problem is first visible

    If OlAppItem.Saved Then
        UpdateStatusAndSave(OlAppItem)
        CreateAppointment = True
    End If

    OutlookApp = Nothing
End Function

为什么不总是创建Outlook.Application对象的实例来保存全局对象呢?

我们找到了一个非常简单的解决方案: 在Outlook中创建/编辑/删除约会之前,我们称之为:

        Dim si As New ProcessStartInfo("Outlook.exe")
        si.WindowStyle = ProcessWindowStyle.Minimized
        Process.Start(si)

它启动了一个真实的,对于用户可见的Outlook实例,只要该实例处于活动状态,与Outlook的连接就不会关闭,因此没有RPC异常

我想我是这样做的,在方法开始时,当我需要它时,我创建了该实例,如果我不再需要它,我关闭它。尝试调用OlAppItem.GetInspector并调用Inspector.Display。保留对Inspector对象的引用,直到完成。