0

WPFアプリ[特にViewModelクラス]で実行を一時停止して再開する方法はありますか? Auto および ManualResetEvent クラスで試しました。しかし、一時停止したいところで一時停止していません。waitone メソッドは実行を一時停止していません。

ビューモデルには、Web サービスを呼び出すメソッドがあります。Web サービスの結果は、別のメソッド [つまり、コールバック メソッド] で取得されます。Web サービスから結果を取得した後、実行を続行したいと考えています。

public void Method1()
{
   for(int i=0; i<5; i++)
   {
      // Call the web service. No waiting for the result.
      // Block the execution here....
   }
}

public void CallBackMethod(int serviceResult)
{
   // After getting the result...
   // I want to continue with Method1...
}

WPF でそれを行う方法はありますか?

4

2 に答える 2

1

あなたはについて話しているManualResetEvent

private ManualResetEvent _reset;

public void Method1()
{  
   _reset = new ManualResetEvent(true);
   for(int i=0; i<5; i++)
   {
       // Call the web service.

       // WaitOne blocks the current thread 
       _reset.WaitOne();
   }
}

public void CallBackMethod(int serviceResult)
{
   // After getting the result...

   // Set allows waiting threads to continue
   _reset.Set();
}
于 2013-06-09T15:39:43.017 に答える