REST API에 연결하고 여러 오브젝트를 가져 오기 위해 여러 엔드 포인트를 호출 중입니다.일련의 메소드를 병렬로 실행하십시오.
RestService<Agent> agentService = new RestService<Agent>(auth, new AgentApi());
RestService<Ticket> ticketService = new RestService<Ticket>(auth, new TicketApi());
RestService<Company> companyService = new RestService<Company>(auth, new CompanyApi());
RestService<Contact> contactService = new RestService<Contact>(auth, new ContactApi());
각 RestService<T>
를 들어 내가 다음 결과 나머지 API를 호출하여 얻을 수 GetAll()
전화 : 장면 GetAll()
뒤에
RestResult<Agent> agentResults = agentService.GetAll();
RestResult<Company> companyResults = companyService.GetAll();
RestResult<Contact> contactResults = contactService.GetAll();
RestResult<Ticket> ticketResults = ticketService.GetAll();
숫자를 만들어 내가 다운로드 할 각 유형에 대한 RestService<T>
작성 HttpWebRequest
재발행
그래서 저는 어떻게 든 4 GetAll()
을 병렬로 호출해야한다고 말합니다. 이론적으로 나는 하나가 아닌 REST API에 여러 요청을 할 수 있습니다.
RestResult<Agent> agentResults;
RestResult<Company> companyResults;
RestResult<Contact> contactResults;
RestResult<Ticket> ticketResults;
Parallel.Invoke(
() => agentResults = agentService.GetAll(),
() => companyResults = companyService.GetAll(),
() => contactResults = contactService.GetAll(),
() => ticketResults = ticketService.GetAll()
);
그러나 변수가 초기화되지 않습니다 것 같습니다 : 내가 가진
하나의 아이디어였다.
이 방법에 대한 제안 사항은 무엇입니까?
"이처럼 보인다"무엇을 의미 하는가 :
가장 쉬운 해결책은 기본값 (
null
)를 수동으로 initalize하는 것입니다? 그들은 여전히 'null'입니까? 그렇다면'GetAll()'메소드가 다른 것을 반환했는지 확인하고 싶습니까? –미안하지만, 나는 나중에 변수를 사용하려고 할 때 변수가 할당되지 않았다는 컴파일 오류가 발생한다는 것을 의미했습니다. – moose56