Click here to Skip to main content
15,743,429 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
here is the below code that is used to get the list of templates from sendgrid using async and await feature. but due to some limitations i cant use these feature in my application which is in .net 3.5/4 and i use vs 2010. i just need the equivalent code which will run at background without using async and await.... im grateful if somebody gives equivalent code without suggesting me to use vs 2012 or using any nugget package....

private static async Task<treturn> GetAsync<treturn>(string getString)

TReturn data =default(TReturn);
using (var client = new HttpClient())

client.BaseAddress = new Uri("");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
Encoding.ASCII.GetBytes(String.Format("{0}:{1}", Credentials.UserName, Credentials.Password))));
HttpResponseMessage response = await client.GetAsync(getString);
if (response.IsSuccessStatusCode)

string t = await response.Content.ReadAsStringAsync();
data =JsonConvert.DeserializeObject<treturn>(t);


return data;

private static async Task<TemplateVersion> GetCurrentTemplate(Template template)

return await GetAsync<TemplateVersion>(String.Format(

template.Versions.Single(s1 =>


private static async Task<TemplatesCollection> GetTemplates()

return await GetAsync<TemplatesCollection>("v3/templates");

private static void Main()

List<Template> templates = GetTemplates().Result.Templates;

Template myTemplate = templates.Single(s1 =>


" Reminder", "n AutoMailer");

private static void SendEmailWebApi(Template template, string subject, string doNotReplyDescription)

// this method will send mail using sendgrid properties by adding from ,to ,subject and attachments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900