如何执行此2操作成为1个操作?实际上我在后台代理中使用但第二个操作无法执行且无法获取值。任何的想法?
public void running()
{
ServiceReference1.WebServiceSoapClient test = new ServiceReference1.WebServiceSoapClient();
test.ReadTotalOutstandingInvoiceCompleted += new EventHandler<ServiceReference1.ReadTotalOutstandingInvoiceCompletedEventArgs>(serviceClient);
test.ReadTotalOutstandingInvoiceAsync();
}
public void serviceClient(object sender, ReadTotalOutstandingInvoiceCompletedEventArgs e)
{
answer = int.parse(e.Result.ToString());
}
更新: 在后台代理:
VibrateController testVibrateControl = VibrateController.Default;
public int answer;
protected override void OnInvoke(ScheduledTask task)
{
//TODO: Add code to perform your task in background
running();
ShellTile t = ShellTile.ActiveTiles.First();
StandardTileData d = new StandardTileData()
{
Title = "U have " + answer + " Invoice!!",
BackTitle = "How Are You!!",
//Count = 0,
// BackBackgroundImage = new Uri("dog.jpg", UriKind.Relative),
// BackgroundImage = new Uri("untitled.png", UriKind.Relative)
};
t.Update(d);
testVibrateControl.Start(TimeSpan.FromSeconds(3));
testVibrateControl.Stop();
//ShellTile.Create(new Uri("/MainPage.xaml?pp=cas", UriKind.Relative), d);
NotifyComplete();
}
在主页:
private void CheckBox_Checked_1(object sender, RoutedEventArgs e)
{
try
{
PeriodicTask p = new PeriodicTask("jj");
p.Description = "Don't push the red button";
ScheduledActionService.Add(p);
//ScheduledActionService.LaunchForTest(p.Name, TimeSpan.FromSeconds(2));
#if (DEBUG_AGENT)
ScheduledActionService.LaunchForTest(p.Name, TimeSpan.FromSeconds(2));
#endif
}
catch (Exception ex)
{
}
}
答案 0 :(得分:0)
在99.9%的情况下,在阻塞的情况下转换异步调用是一个坏主意,所以我很想知道你为什么需要它。
如果从未执行第二个操作,则可能存在服务器端或连接问题。鉴于您正在使用WCF服务,请使用WCF Test Client检查返回的结果是否符合您的预期。
据我所知,NotifyComplete
在您的回调被触发之前被调用,这很可能就是问题所在。虽然所有其他调用都已逐步执行,但是存在潜在的竞争条件,其中回调的速度不足以在代理执行完成向操作系统发出信号之前被触发。
您可以做的是在内部包装回调。像这样:
ServiceReference1.WebServiceSoapClient test = new ServiceReference1.WebServiceSoapClient();
test.ReadTotalOutstandingInvoiceCompleted += (s,e) =>
{
// Do some things here
NotifyComplete();
};
test.ReadTotalOutstandingInvoiceAsync();
从那里开始,为什么不让它返回int
开始,这样你就不必解析它了?