Это только идея о том, что я делаю в службе окна. Я получаю идею от этого video, чтобы сделать это в параллельной обработке.Вызов метода асинхронного ожидания при вызове метода синхронизации
У меня есть два разных метода и класс модели.
Код модели Класс:
public class Email(){
public string Recipient { get; set; }
public string Message { get; set; }
}
Методы это что-то вроде этого:
public void LoadData(){
while(Main.IsProcessRunning){
// 1. Get All Emails
var emails = new dummyRepositories().GetAllEmails(); //This will return List<Emails>.
// 2. Send it
// After sending assume that the data will move to other table so it will not be query again for the next loop.
SendDataParallel(emails);//this will function async? even though the calling method is sync.
// This will continue here or wait until it already send?
// If it will continue here even though it will not send already
// So there's a chance to get the email again for the next loop and send it again?
}
}
//This will send email at parallel
public async void SendDataParallel(IList<Email> emails){
var allTasks = emails.Select(SendDataAsync);
await TaskEx.WhenAll(allTasks);
}
//Assume this code will send email asynchronously. (this will not send email, for sample only)
public async void SendDataAsync(Email email){
using (var client = new HttpClient())
{
client.PostAsync(email);
}
}
Я только хочу, чтобы получить все очереди сообщений электронной почты затем отправить его параллельно, то подождите, пока он уже не отправить. Я избегаю использования foreach
на каждое электронное письмо, которое я получаю.
В чем проблема? –
@SriramSakthivel уже отредактирован.,. – janmvtrinidad
@janmvtrinidad Здесь до сих пор нет вопроса. –