I need to send an email after the end user has entered some text. I would like to do this on another thread, so the user does not notice any performance issues. I have tried creating a delegate to handle it, but calling RenderTemplate fails, and I think it is because the HttpContext is null. Is there any other way of rendering a template which can be done async?
Have you considered using /base for this? :-) That's what I usually do. Then on the callback, check if the response from the base method is "true" (if that's what it's returning or simply check if the success variable is not null. If it's "true" or not null, manipulate the UI using jQuery.
I haven't tried /Base (I am fairly new to Umbraco). Since this is an email I would like to render and then send, I wouldn't be able to manipulate it with jQuery. I would expect that I need to render the HTML on the server and then send that as an email.
Correct me if I am wrong here, just trying to get a overview of what you want to achieve :-)
- The enduser (in this case, the visitor of the webpage) is presented with a form to fill out the email details, like Subject, BodyText, from email etc. - Once he hits the "Send/Submit" button it will be send to an email specified in the backend without doing a postback.
The user is asked to provide som feedback in a form. When hitting submit, the email is sent. If I render the emailtemplate and send the email on the calling thread, there is some delay for the user. I would like the user to just hit submit, and then handle the email sending on a background thread. Right now I am using a delegate to run the code which sends the email. But then I cannot use renderTemplate and I think it is because HttpContext is null
Alright, so without having looked at your code, I think you might be able to do something like this in your codebehind (I guess you're using a UserControl for this, right?):
public void SendEmails() { // Your logic to send e-mails here }
protected void btnInvokeThread(object sender, EventArgs e) { // This invokes a new non-threadpool thread with your method which needs to return void Thread t = new Thread(SendEmails); t.IsBackground = true; t.ThreadPriority = ThreadPriority.Lowest; t.Start();
// Call umbraco.library.RenderTemplate() here to show the new template. }
thanks for the code. It does work, but it does not quite solve my problem. Your code shows how to send the email on another thread, and I already solved that using delegates. The problem is using renderTemplate on another thread and THEN send the email. For know I will just be using renderTemplate on the calling thread, so I haven't been able to use it on another thread.
RenderTemplate async
Hi,
I need to send an email after the end user has entered some text. I would like to do this on another thread, so the user does not notice any performance issues. I have tried creating a delegate to handle it, but calling RenderTemplate fails, and I think it is because the HttpContext is null. Is there any other way of rendering a template which can be done async?
thanks
Thomas
Hi Thomas,
Have you considered using /base for this? :-) That's what I usually do. Then on the callback, check if the response from the base method is "true" (if that's what it's returning or simply check if the success variable is not null. If it's "true" or not null, manipulate the UI using jQuery.
- Bo
Hi Bo,
I haven't tried /Base (I am fairly new to Umbraco). Since this is an email I would like to render and then send, I wouldn't be able to manipulate it with jQuery. I would expect that I need to render the HTML on the server and then send that as an email.
-Thomas
Hi Thomas,
Correct me if I am wrong here, just trying to get a overview of what you want to achieve :-)
- The enduser (in this case, the visitor of the webpage) is presented with a form to fill out the email details, like Subject, BodyText, from email etc.
- Once he hits the "Send/Submit" button it will be send to an email specified in the backend without doing a postback.
Is this the workflow?
- Bo
Yes, that is it more or less.
The user is asked to provide som feedback in a form. When hitting submit, the email is sent. If I render the emailtemplate and send the email on the calling thread, there is some delay for the user. I would like the user to just hit submit, and then handle the email sending on a background thread. Right now I am using a delegate to run the code which sends the email. But then I cannot use renderTemplate and I think it is because HttpContext is null
best regards
Thomas
Hi Thomas,
Alright, so without having looked at your code, I think you might be able to do something like this in your codebehind (I guess you're using a UserControl for this, right?):
Let me know if this works for you :-)
- Bo
Hi Bo,
thanks for the code. It does work, but it does not quite solve my problem. Your code shows how to send the email on another thread, and I already solved that using delegates. The problem is using renderTemplate on another thread and THEN send the email. For know I will just be using renderTemplate on the calling thread, so I haven't been able to use it on another thread.
thanks
Thomas
is working on a reply...