2016-11-18 3 views
0

私は、オブジェクトをキャッシュする空白のサービスファブリックアプリケーション/サービスを構築しました。以下のコードでは、サービスを呼び出すコンソールウィンドウでクライアントを作成しました。 c.Addにブレークポイントを置き、それをステップオーバーすると、プログラムは終了します。例外はスローされず、 "done"は出力されず、プログラムはコード0で終了します。 サービスは実行中であり、正常な状態です。私は何が間違っているかを見つけるために何ができますか?サービスファブリッククライアントはただ終了します

class Program 
{ 
    static void Main(string[] args) 
    { 
     Test(); 
    } 

    static async void Test() 
    { 
     Uri serviceName = new Uri("fabric:/CacheApp/PreorderCache"); 
     ServicePartitionResolver resolver = new ServicePartitionResolver(() => new System.Fabric.FabricClient()); 
     NetTcpBinding binding = (NetTcpBinding)WcfUtility.CreateTcpClientBinding(); 

     Client c = new Client(new WcfCommunicationClientFactory<IPreorders>(binding, null, resolver), serviceName, 1); 

     try 
     { 
      PreOrder po = await c.Get("50", "11001", OrderNumber = "123456" }); 
      Console.WriteLine("done"); 
     } 
     catch (Exception ex) 
     { 
      Console.WriteLine(ex.ToString()); 
     } 
    } 
} 

調査後、サービス内で使用されているトランザクションと関係があるようです。

サービスは決してここに過去

await tx.CommitAsync(); 

を取得していないサービスでフォルトコード、

await preOrders.GetAsync(tx, d, s, (k, v) => preOrder); 
ServiceEventSource.Current.ServiceMessage(this, "after update"); 
await tx.CommitAsync(); 
ServiceEventSource.Current.ServiceMessage(this, "after commit"); 

答えて

1

Test何も特別なMainから待望されていない非同期メソッドがあるのです。したがって、あなたのプログラムはTestが完了するのを待つことはありません。

GetAwaiter().GetResult()を追加すると、Testメソッドは通常のメソッドのように動作し、c.Get()が完了するまでブロックされます。

オプション2を使用し、 'async'を削除してください。

(非同期イベントハンドラにasync voidの使用を予約します)

関連する問題