c# - C# 错误:委托是本地函数,因此必须始终有一个主体
问题描述
试图将Winform应用程序中的代码模仿为VSTO 加载项。它在 Winform 中工作,但在 VSTO 应用程序的ThisAddIn类中出现以下错误。问题:我怎样才能让它在 VSTO 插件中也能工作?
错误:
委托是本地函数,因此必须始终有一个主体
Winform 的 Form 类中的相关代码[有效]:
/// <summary>This event handler is called when myApp.exe closes.</summary>
void p_Exited(object sender, EventArgs e)
{
// remove the event
((Process) sender).Exited -= p_Exited;
// the UI thread is running asynchronous to myApp.exe closing
// that's why we can't call CheckIfPassed(); directly
Invoke(new IsPassedDelegate(CheckIfPassed));
}
delegate void IsPassedDelegate();
VSTO App 的 ThisAddIn 类中的相关代码[在最后一行给出错误:'delegate void IsPassedDelegate();']:
/// <summary>This event handler is called when myApp.exe closes.</summary>
void p_Exited(object sender, EventArgs e)
{
// remove the event
((Process) sender).Exited -= p_Exited;
// the UI thread is running asynchronous to myApp.exe closing
// that's why we can't call CheckIfPassed(); directly
Dispatcher.CurrentDispatcher.Invoke(new IsPassedDelegate(CheckIfPassed));
}
delegate void IsPassedDelegate();
解决方案
推荐阅读
- javascript - 如何在具有 id 的容器下方向下滚动一定数量的像素?
- rust - 在 Rust 中创建带有谓词函数向量的结构
- python - Python 套接字连接 - 为什么会出现此错误?
- c - 我自己的子字符串函数 | valgrind 显示一些我不明白的 malloc 错误
- odoo - Odoo 12 数据库恢复
- python - 在 Python 中以某种方式打印二维数组
- bash - shell glob 扩展如何像 ls -l * 一样工作?
- html - 如何使用 CSS 最小化 iframe 垂直空间?
- c++ - 如何在 Qt SCXML 状态图中使用条件转换
- mysql - 如何用 mysql 对子字符串进行分组?