I am using asp.net v4 C # and I have a list of email addresses. I want one of my administrators to be able to enter a message, click "SEND" and send emails one at a time.
Best way, in my opinion, to use async methods in .net? OnClick from the submit button, I take a list of email addresses, then call the async method. I just don't know how to get it to scroll through the list one by one and turn off the email.
You must complete one at a time so that I can save a copy of the letter sent against this user account.
Here is what I still have (cobblestone from textbooks / posts here)
protected void btnSend_Click(object sender, EventArgs e)
{
List<string> emails = new List<string>();
emails.Add("test1@test.com");
emails.Add("test2@test.com");
emails.Add("test3@test.com");
emails.Add("test4@test.com");
emails.Add("test5@test.com");
emails.Add("test6@test.com");
emails.Add("test7@test.com");
SendingDelegate worker = new SendingDelegate(DoSend);
AsyncCallback completedCallback = new AsyncCallback(DoSendCompletedCallBack);
lblThreadDetails.Text = "sending to " + emails.Count.ToString() + " email addresses";
worker.BeginInvoke(completedCallback, AsyncOperationManager.CreateOperation(null));
sending = true;
}
private bool sending = false;
private delegate bool SendingDelegate();
private bool DoSend()
{
lblThreadDetails.Text = "processing " + x.ToString();
Thread.Sleep(1000);
return false;
}
private void DoSendCompletedCallBack(IAsyncResult ar)
{
SendingDelegate worker = (SendingDelegate)((AsyncResult)ar).AsyncDelegate;
bool success = worker.EndInvoke(ar);
sending = false;
if (success)
{
lblThreadDetails.Text = "all done!";
}
}
I basically need to put the async function call in a loop where I look at the list of email addresses.
?