Closed kavithakolishetty closed 4 years ago
@kavithakolishetty Hi, you shouldn't use blocking calls like Wait form UIthread in WinForms. Better to use Dispatcher to move to the work into the background thread, or at least make the button click handler async:
private async void btnSendEmail_Click(object sender, EventArgs e)
{
await RunAsync(txtTo.Text, txtFrom.Text, txtSubject.Text, txtBody.Text);
}
I've added a comment to the readme to omit such issues.
Below method is getting into deadlock. I'm not able to use postasync in windows form button click.
please help me to resolve this.
I have also tried without await, but still the same.
private void btnSendEmail_Click(object sender, EventArgs e) { RunAsync(txtTo.Text, txtFrom.Text, txtSubject.Text, txtBody.Text).Wait(); }
static async Task RunAsync(string To,string From, string Subject,string Body) { MailjetClient client = new MailjetClient("95f23726a201bc9f9034dfd921ffb04e", "7d99b5e37c0b823d5780aa0aba74c6ec") { Version = ApiVersion.V3_1, }; MailjetRequest request = new MailjetRequest { Resource = Send.Resource, } .Property(Send.Messages, new JArray { new JObject { {"From", new JObject { {"Email",From}, {"Name", "Me"} }}, {"To", new JArray { new JObject { {"Email", To}, {"Name", "You"} } }}, {"Subject", Subject}, {"TextPart", "Greetings from DigiCorro"}, {"HTMLPart", Body} } }); try {