2017-01-05 2 views
0

WPF에서 작동하는 gRPC C# 예제를 얻으려고합니다.
콘솔 응용 프로그램 내에서 작동하는 동일한 코드가 작동하지 않습니다.
내가 무엇을 놓치고 있습니까? 콘솔 응용 프로그램에서 작동 및 WPF에서 작동하지 않습니다 최소 클래스는 다음과 같습니다가 걸려된다WPF가 작동하지 않는 gRPC

public class GrpcClientImpl 
    { 
     private GrpcService.GrpcService.GrpcServiceClient client; 
     public GrpcTestClientImpl() 
     { 
      var channel = new Channel("127.0.0.1:6980", ChannelCredentials.Insecure); 
      client = new GrpcService.GrpcService.GrpcServiceClient(channel); 
      ProcessFeed().Wait(); 
     } 
     public async Task ProcessFeed() 
     { 
      try 
      { 
       using (var call = client.Feed(new FeedRequest())) 
       { 
        var responseStream = call.ResponseStream; 
        while (await responseStream.MoveNext()) 
        { 
         var result = responseStream.Current; 
         Console.WriteLine("received result"); 
        } 
       } 
      } 
      catch (RpcException e) 
      { 
       Console.WriteLine("RPC failed " + e); 
       throw; 
      } 
     } 
    } 

responseStream.MoveNext는()입니다. 보낸 항목에 응답하지 않으며 gRPC 서버가 없으면 예외를 트리거하지 않습니다. 나는 무엇을 놓쳤는가?

답변

2

문제는 생성자 내에서 ProcessFeed().Wait(); 호출을 차단하는 것입니다. http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html

이 문제를 해결 (안 costructor에서) 외부에서 await ProcessFeed();를 호출하려면 :

이 게시물이

이유를 설명합니다.

+0

불행히도 내 요구 사항은 피드를 듣고 싶을 때 시작 중에 호출하는 것입니다. – weismat

+0

Ok - 이제 처리 대기를위한 추가 작업이 시작됩니다. – weismat

관련 문제