아래 WebApi 컨트롤러가 있습니다. 이 컨트롤러에는 내부적으로 CustomerDataService이라는 고객 레코드 업데이트 서비스를 호출하는 Update 메서드가 있습니다. 업데이트 할 고객 레코드가 있습니다.아래에 설명 된 시나리오에서 비동기 적으로 일부 작업을 수행하는 C#으로 서비스를 만드는 방법은 무엇입니까?
CustomerDataService의 UpdateMethod가 업데이트를 수행하고 업데이트 응답을 반환합니다.
데이터 조작/데이터 캐시 관리와 같은 업데이트 응답 후에 비동기 적으로 처리해야하는 요구 사항이 있습니다. Update가 성공적으로 수행되면서이 처리는이 API의 사용자와 관련이 없으므로 시간이 오래 걸리기 때문에이 작업을 비동기 적으로 수행해야합니다. 주어진 시나리오에서 C#으로이 작업을 수행 할 수 있습니까? 제발 제안 해주세요.
참고 :가 나는 사용자 세션이 특정 작업 (들)을 수행 할로 이것을 달성하기 위해 어떠한 배치 작업을 생성하고 싶지 않아요.
컨트롤러
public class CustomerController : ApiController
{
[HttpGet]
public string UpdateCustomer()
{
ICustomerService obj = new CustomerDataService();
return obj.UpdateCustomer(GetCustomerList());
}
private List<CustomerModel> GetCustomerList()
{
return new List<CustomerModel>()
{
new CustomerModel
{
CustomerId="1",
Name="John",
Category="P1"
},
new CustomerModel
{
CustomerId="2",
Name="Mike",
Category="P2"
}
//....n Records
};
}
}
모델
[Serializable]
[DataContract]
public class CustomerModel
{
[DataMember]
public string CustomerId { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Category { get; set; }
}
인터페이스 및 CustomerDataService
public interface ICustomerService
{
string UpdateCustomer(List<CustomerModel> customerList);
}
public class CustomerDataService : ICustomerService
{
public string UpdateCustomer(List<CustomerModel> customerList)
{
//Do Data Processing - DB Call
//Return Confirmation Message
return "Data Updated Successfully!!!";
//Needs to perform some processing asynchronously i.e. Call ProcessResults()
}
private void ProcessResults()
{
//DO Processing
}
}