首页 > 解决方案 > 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();

标签: c#vsto

解决方案


推荐阅读