I need to create a newsletter distribution group and add about 4,000 subscriber email addresses to it via the API from a web page. My email addresses are coming from another database (non-Sitefinity).
I wrote and tested the code locally, but it took about 10 to 15 minutes to process. When I deploy it to the server, it dies at 3 minutes due to a timeout. Even if I could increase the timeout limit, I don't like that approach because waiting 10 minutes for a web page to process is just way too long.
Is there a way, via the API, to somehow have Sitefinity run a background thread that continues to process, but allows the web page to post back almost immediately?
What I have in mind is something like when you send a itefinity newsletter. The newsletter admin page doesn't actually wait for each email to be sent, but displays a message that it's still running in the background with instructions on how to monitor the progress.
My other idea is to code my page such that it only tries to do a fixed number of rows per page load, like 100, and uses a session variable to know when to stop trying to add more subscribers to the group. I think it would work, but doesn't seem very graceful.
Here is the code I have thus far...
sender, EventArgs e)
//create the group
String groupName = DateTime.Today.Year.ToString() +
" Membership Renewal"
IGroup group = dataManager.CreateGroup();
group.GroupName = groupName;
MembersUpForRenewalTA ta =
MembershipRenewalDataSet.MembersUpForRenewalDataTable membersUpForRenewal = ta.GetData();
AddSubscriberToGroup(group, memberUpForRenewal.email, memberUpForRenewal.fname, memberUpForRenewal.lname);
//Go to Sitefinity Newsletter admin screen
AddSubscriberToGroup(IGroup Group, String Email, String FirstName, String LastName)
//try to find the subscriber email
ISubscriber subscriber = dataManager.GetSubscriber(Email);
//email doesn't exist, so create and save a new subscriber
subscriber = dataManager.CreateSubscriber(Email);
subscriber.FirstName = FirstName;
subscriber.LastName = LastName;
//see if the subscriber is already a member of the group
IGroupSubscriber groupSubscriber = dataManager.GetGroupSubscriberRelation(Group.GroupId, subscriber.SubscriberId);
//CONTINUE: subscriber is not a member of the list, so create and save the relationship
groupSubscriber = dataManager.CreateGroupSubscriberRelation(Group.GroupId, subscriber.SubscriberId);