private void GeoCode_Method1(string myaddress, int waypointIndex, string callingUser)
{
GCService.GeocodeCompleted += new EventHandler<NSpace.GCService.GeocodeCompletedEventArgs>(GeoCode_Method1_GeocodeCompleted);
GCService.GeocodeAsync(request, waypointIndex);
}
void GeoCode_Method1_GeocodeCompleted(object sender, NSpace.GCService.GeocodeCompletedEventArgs e)
{
//***QUESTION: how do I access variable "callinguser" from GeoCode_Method1 in this method??
}
Run Code Online (Sandbox Code Playgroud)
当我调用 GeoCode_Method1 时,我发送“callinguser”字符串变量,并且我想在 GeoCode_Method1_GeocodeCompleted 中访问它(异步 GeoCodingAsync 调用完成时触发)。我该怎么做呢?
最简单的方法是使用 C# lambda 表达式作为事件处理程序。然后,该 lambda 表达式可以调用该GeoCode_Method1_GeocodeCompleted方法并传递callinguser参数。
GCService.GeocodeCompleted +=
(sender, e) => GeoCode_Method1_GeocodeCompleted(callinguser, sender, e);
GCService.GeocodeAsync(request, waypointIndex);
void GeoCode_Method1_GeocodeCompleted(
string callingUser,
object sender,
Space.GCService.GeocodeCompletedEventArgs e) {
//***QUESTION: how do i access variable "callinguser" from GeoCode_Method1 in this method??
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2238 次 |
| 最近记录: |