C# C语言中的回调函数#

C# C语言中的回调函数#,c#,asynchronous,methods,callback,C#,Asynchronous,Methods,Callback,我必须用回调(异步)、result..等调用api(SOAP)。 我必须使用的方法: public IAsyncResult BeginInsertIncident( string userName, string password, string MsgId, string ThirdPartyRef, string Type, string EmployeeId, string ShortDescription, string Details, string Cate

我必须用回调(异步)、result..等调用api(SOAP)。 我必须使用的方法:

public IAsyncResult BeginInsertIncident(
    string userName, string password, string MsgId, string ThirdPartyRef,
    string Type, string EmployeeId, string ShortDescription, string Details,
    string Category, string Service, string OwnerGrp, string OwnerRep,
    string SecondLevelGrp, string SecondLevelRep, string ThirdLevelGrp,
    string ThirdLevelRep, string Impact, string Urgency, string Priority,
    string Source, string Status, string State, string Solution,
    string ResolvedDate, string Cause, string Approved, AsyncCallback callback,
    object asyncState);

EndInsertIncident(IAsyncResult asyncResult, out string msg);
EndInsertInsident关闭票证系统中的请求,如果票证正确完成,则给出结果

现状:

server3.ILTISAPI api = new servert3.ILTISAPI();
api.BeginInsertIncident(username, "", msg_id, "", "", windows_user,
    "BISS - Software Deployment", "", "", "NOT DETERMINED", "", "", "", "", "",
    "", "5 - BAU", "3 - BAU", "", "Interface", "", "", "", "", "", "", null,
    null);
那么,现在,我如何实现回调函数呢? api“InsertInsidentCompleted”的状态已经为空,因为我认为我不调用EndInsertInsident

我是C语言新手,需要一些帮助。

是一个委托,返回void并接受一个类型为
IAsyncResult
的参数

因此,使用此签名创建一个方法,并将其作为倒数第二个参数传递:

private void InsertIncidentCallback(IAsyncResult result)
{
    // do something and then:
    string message;
    api.EndInsertIncident(result, out message);
}
这样传递:

api.BeginInsertIncident(username, "", msg_id, "", "", windows_user,
    "BISS - Software Deployment", "", "", "NOT DETERMINED", "", "", "", "", "",
    "", "5 - BAU", "3 - BAU", "", "Interface", "", "", "", "", "", "",
    InsertIncidentCallback, null);
private void InsertIncidentCallback(server3.ILTISAPI api, IAsyncResult result)
{
    // do something and then:
    string message;
    api.EndInsertIncident(result, out message);
}
如果您不能将
api
作为类的成员变量并希望将其传递给回调函数,则必须执行以下操作:

api.BeginInsertIncident(username, "", msg_id, "", "", windows_user,
    "BISS - Software Deployment", "", "", "NOT DETERMINED", "", "", "", "", "",
    "", "5 - BAU", "3 - BAU", "", "Interface", "", "", "", "", "", "",
    InsertIncidentCallback, null);
private void InsertIncidentCallback(server3.ILTISAPI api, IAsyncResult result)
{
    // do something and then:
    string message;
    api.EndInsertIncident(result, out message);
}
要将其作为回调传递,您必须使用委托:

api.BeginInsertIncident(..., r => InsertIncidentCallback(api, r), null);

@ManuelFischer:您需要使
api
成为包含您的方法的类的成员变量。我是否可以使用api变量调用methode InsertIncidentCallback,如….InsertIncidentCallback(api),null)@ManuelFischer:请查看更新。好的,现在我有一个错误代码“CS1525”>无效表达式。我不知道运营商=>?你的目标是什么版本的.NET
=>
是lambda运算符。旁注:有史以来最差的函数签名。