Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas Dolberg 74 posts 95 karma points
    Dec 02, 2011 @ 11:12
    Thomas Dolberg
    0

    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

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Dec 02, 2011 @ 12:01
    Bo Damgaard Mortensen
    0

    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

  • Thomas Dolberg 74 posts 95 karma points
    Dec 02, 2011 @ 13:35
    Thomas Dolberg
    0

    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

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Dec 03, 2011 @ 17:07
    Bo Damgaard Mortensen
    0

    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 

     

  • Thomas Dolberg 74 posts 95 karma points
    Dec 03, 2011 @ 21:05
    Thomas Dolberg
    0

    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

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Dec 04, 2011 @ 01:22
    Bo Damgaard Mortensen
    0

    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?):

    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.

    Let me know if this works for you :-)

    - Bo

  • Thomas Dolberg 74 posts 95 karma points
    Dec 06, 2011 @ 00:34
    Thomas Dolberg
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft