在异步委托调用中发送可选参数

时间:2014-09-24 08:06:09

标签: c# delegates

以下是我的代表签名:

public delegate PrintAllergyClass AllergiesDelegate(
    long patientAccount, long chartId, bool isCf, string practiceCode = "");

以下是我的称呼方式:

AllergiesDelegate allergies = new AllergiesDelegate(
    GetChartFacadeObj().LoadAllergyPrintData);
IAsyncResult Allergies = allergies.BeginInvoke(
    long.Parse(patientAccount), long.Parse(chartID), Is_CF, null, null);

以下是功能签名:

public PrintAllergyClass LoadAllergyPrintData(
    long PAcc, long ChartID, bool Is_CF, string PracticeCode="")

但它给了我错误:

  

方法没有超载' BeginInvoke'需要5个参数。

在intellisense上,它按预期显示所需的参数。

请指导我,如何处理这个案子?

1 个答案:

答案 0 :(得分:1)

Intellisense向您展示如何调用该委托:

enter image description here

可以提供两个额外的基础结构参数。委托签名中的可选参数不会转移到委托的BeginInvoke方法。

    public delegate object AllergiesDelegate(
        long patientAccount, long chartId, bool isCf, string practiceCode = "");

    static void Main(string[] args)
    {
        AllergiesDelegate allergies = null;
        IAsyncResult Allergies = allergies.BeginInvoke(0, 0, false, "", null, null);
    }