Quantcast
Channel: OutSystems Community
Viewing all articles
Browse latest Browse all 1476385

[Forums] Asynchronous programming in .net Extensions

$
0
0

Timothy May wrote:

Mikko Nieminen wrote:

After my first post, I had refactored the code, pretty much as you suggested:

namespace OutSystems.NssSendGridExt {
public class CssSendGridExt: IssSendGridExt {
public void MssSendTestEmail(out string ssResult) {
            TaskSendTestEmail().Wait();
            ssResult = "";
// TODO: Write implementation for action
} // MssSendTestEmail
        static async Task  TaskSendTestEmail()
        {
            var apiKey = "---------redacted-----------";
            var client = new SendGridClient(apiKey);
            var from = new EmailAddress("tmay@inscico.com", "Example User tmay");
            var subject = "Test02: Sending with SendGrid is Fun";
            var to = new EmailAddress("tmay@inscico.com", "Example User tmay");
            var plainTextContent = "and easy to do anywhere, even with C#";
            var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
            var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
            var response = await client.SendEmailAsync(msg);
        }
    } // CssSendGridExt
} // OutSystems.NssSendGridExt

The code does send an email but it never returns to the caller. I don't see anything strange in this simple code but I'm not familiar with the innards of C# async. My next step would be to write a little standalone scaffolding program to test all of this without the OutSystems overhead. I'm curious as to why this never returns and would want to make sure it is something in my code and not an unwelcome side-effect of using async in an Outsystems Extension.

Also, after reading your post I think I will try using the SendGrid REST API to send emails and WebHooks to get notifications of delivery status etc. That would avoid having to use an Extension. I'll let you guys know how that turns out.

Thanks!


Hi Timothy, 

I', having the same problem !

Something as simple as 

public void MssmyTask(out string ssResult) {
            myTask.Wait();
            ssResult = "done";
}
        static async Task  myTask()
        {
              Task.Run(() =>
              {
                  int i = 0;
                  while (i < 5)
                  {
                      Console.WriteLine(i);
                      i++;
                      Thread.Sleep(500);
                  }
              }
              );
        }


Won't ever return!
Did you manage to find a workaround ?


Viewing all articles
Browse latest Browse all 1476385

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>