2014-09-18 2 views
1

그래서 서비스 호출을 보내는 작업이 있습니다 ...이 작업에는 호출이 반환 될 때 프로그램이 데이터를 정렬 할 수 있도록 연속 작업이 있습니다. 이제는 호출이 데이터와 함께 반환 될 때 UI 스레드를 차단하지 않고 해당 데이터를 기반으로 다른 서비스 호출을 작성하기를 바랍니다. 이것이 가능한가?UI를 차단하지 않으려는 작업 내에서 중첩 작업 스레드

내 예제 코드는 지금까지 있습니다 : 누군가가이 작업을 수행하는 방법에 대한 더 많은 정보를 원하는

Task t = new Task(() =>{//Make my service call}; 
t.Start(); 
t.ContinueWith((sender) => 
{ 
    //sort my data out 
    //when thats done make another service call based on that data that doesn't 
    // block UI thread 
}, cts.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext()); 
+0

도움 너 사용하고있어? 서비스 호출은 동기식입니까? – bit

+0

WCF를 사용하고 있으며 동기식입니다. 나는 또한 닷넷 4를 사용하고 비동기식/누드 킷 패키지에 의존하기를 원하지 않는다고 언급해야한다. – user1

+0

그럼 우리는 여기에 복제본이있다. http://stackoverflow.com/questions/18889862/using-asynchronous-tasks -to-call-synchronous-wcf-service – bit

답변

0

경우

void MyMethod() 
{ 
    Task t = new Task(() =>{//Make my service call}; 
    t.Start(); 
    t.ContinueWith((sender) => 
    { 
     //sort my data out 
     //when thats done make another service call based on that data that doesn't 
     // block UI thread 

     BackgroundWorker bw = new BackgroundWorker(); 
     bw.DoWork += bw_DoWork; 
     bw.RunWorkerAsync(); 
    }, cts.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext()); 
} 

void bw_DoWork(object sender, DoWorkEventArgs e) 
{ 
    //do some stuff 
} 

이 무료 전자 책 - Threading in C# by Joseph Albahari은 무엇 서비스를 많이