- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
To detect that Outlook is shutting down, you can use the Quit event of the Application object in the Outlook object model to receive a notification that the process is shutting down. Be sure that you respond quickly to the event and return control to Outlook as quickly as possible.
不过好像只能在VB.Net里做,C#不让。有一个名为 Quit() 的方法和一个名为 Quit 的事件,当我尝试将事件处理程序连接到该事件时,C# 编译器说您不能在方法组上使用 +=。
顺便说一句,我试过了:您也不能创建在 C# 中具有相同名称的事件和方法。语言不允许。
下面的示例是 Outlook 插件的 VSTO 项目模板代码,仅添加了一个方法 QuitHandler,并尝试将其挂接到 Quit 事件。
当您输入代码时,intellisense 将同时显示 Quit 事件和 Quit 方法以供选择,但选择事件会导致代码无法编译。
有没有办法明确告诉编译器这是您打算使用的退出事件?
namespace OutlookAddIn2
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Application.Quit += MyQuitHandler;
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// Note: Outlook no longer raises this event. If you have code that
// must run when Outlook shuts down, see https://go.microsoft.com/fwlink/?LinkId=506785
}
void MyQuitHandler()
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
编译器输出(您可以忽略 en-US 警告,据我所知,我在所有版本的 Visual Studio 中都遇到过这种情况,据我所知,这是由于在同一台机器上安装 Office 和 Visual Studio 造成的。)
1>------ Build started: Project: OutlookAddIn2, Configuration: Debug Any CPU ------
1>CSC : warning CS2038: The language name 'en-US' is invalid.
1>D:\Temp\OutlookAddIn2\ThisAddIn.cs(7,10,7,26): error CS1656: Cannot assign to 'Quit' because it is a 'method group'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
当我在 VB.Net 中尝试相同时,问题不存在,编译正常:
Public Class ThisAddIn
Private Sub ThisAddIn_Startup() Handles Me.Startup
AddHandler Application.Quit, AddressOf MyQuitHandler
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
End Sub
Private Sub MyQuitHandler()
End Sub
End Class
这是使用 Vusual Studio 2017 和 Resharper 2017.3.1。
我不认为 Resharper 在这种特殊情况下是罪魁祸首:当它的符号缓存变坏时,我看到过类似的错误消息,但这永远不会导致无法编译的代码。相反,它会导致编译和工作的代码尽管代码编辑器指出的错误。
[编辑]顺便说一句,它也不是这样工作的,我认为它无论如何都是隐式的
Application.Quit += new ApplicationEvents_11_QuitEventHandler(MyQuitHandler);
最佳答案
重复 No Application Quit event in Outlook?
答案(我测试并确认有效):
((Outlook.ApplicationEvents_11_Event)Application).Quit
+= new Outlook.ApplicationEvents_11_QuitEventHandler(ThisAddIn_Quit);
void ThisAddIn_Quit()
{
System.Windows.Forms.MessageBox.Show("bye bye problem, I found the solution!!");
}
关于c# - 在 Outlook VSTO 加载项中,C# 不允许您将事件处理程序挂接到 Application.Quit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56537728/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!