0

この2つの操作を1つの操作にする方法は? 実際にはバックグラウンド エージェントで使用しましたが、2 番目の操作を実行できず、値を取得できません。何か案が?

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)
            {
            }
        }
4

1 に答える 1

0

99.9% のケースで、非同期呼び出しをブロック呼び出しに変換するのは悪い考えです。なぜそれが必要なのか知りたいです。

2 番目の操作が実行されない場合は、サーバー側または接続に問題がある可能性があります。WCF サービスを使用している場合は、WCF テスト クライアントを使用して、返された結果が期待どおりかどうかを確認します。

私が知る限りNotifyComplete、コールバックがトリガーされる前に呼び出されます。これが問題である可能性が最も高いです。他のすべての呼び出しはステップスルーされますが、エージェント実行の完了が OS に通知される前にコールバックがトリガーされるほど速くないという競合状態が発生する可能性があります。

あなたができることは、コールバックを内部的にラップすることです。このような:

ServiceReference1.WebServiceSoapClient test = new ServiceReference1.WebServiceSoapClient();
test.ReadTotalOutstandingInvoiceCompleted += (s,e) =>
{
   // Do some things here
   NotifyComplete();
};

test.ReadTotalOutstandingInvoiceAsync();

そこからint先に進み、解析する必要がないように、最初から を返さないのはなぜですか?

于 2013-03-12T01:58:05.543 に答える