<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>C# on Andrea Azzola</title><link>https://andreaazzola.com/categories/c%23/</link><description>Recent content in C# on Andrea Azzola</description><generator>Hugo -- 0.150.1</generator><language>en-us</language><lastBuildDate>Thu, 27 Mar 2014 00:00:00 +0000</lastBuildDate><atom:link href="https://andreaazzola.com/categories/c%23/index.xml" rel="self" type="application/rss+xml"/><item><title>Search Email Inbox with C#</title><link>https://andreaazzola.com/post/search-email-inbox-csharp/</link><pubDate>Thu, 27 Mar 2014 00:00:00 +0000</pubDate><guid>https://andreaazzola.com/post/search-email-inbox-csharp/</guid><description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note (2025):&lt;/strong&gt; This post dates back to 2014 and uses password‑based IMAP access for Gmail. Modern Gmail/Google Workspace typically requires &lt;strong&gt;OAuth 2.0&lt;/strong&gt; and app passwords/“less secure apps” are disabled. The example is kept for archival purposes; adapt authentication accordingly in new projects.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;A few years ago I helped manage a &lt;a href="https://magmaglobalgroove.com" target="_blank" rel="noopener" title="Visit MaGmA Global Radio"&gt;radio&lt;/a&gt; and I needed a tool—an &lt;em&gt;ASP.NET&lt;/em&gt; web page—for the periodical download of promo mixes. They were linked in emails recognizable by a few keywords.&lt;/p&gt;</description></item><item><title>Call async methods with C#</title><link>https://andreaazzola.com/post/call-async-method/</link><pubDate>Thu, 15 Oct 2009 00:00:00 +0000</pubDate><guid>https://andreaazzola.com/post/call-async-method/</guid><description>&lt;p&gt;&lt;em&gt;Note: This article was originally written in 2009 and may be obsolete due to C# technology improvements.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This article shows how to delegate work to an asynchronous thread in C#, allowing for code execution and app responsiveness. You might go a step further by implementing error notifications, polling, or waiting for the procedure to complete at a certain point.&lt;/p&gt;
&lt;p&gt;Suppose you have the following method:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-cs" data-lang="cs"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;public&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;void&lt;/span&gt; UploadFile(&lt;span style="color:#66d9ef"&gt;string&lt;/span&gt; path)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;try&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;//... uploads some file to the server&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;catch&lt;/span&gt;(Exception ex)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;// ... handle errors&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And you are implementing it as a web service: you are asked to give an immediate response and upload the file &lt;em&gt;asynchronously&lt;/em&gt;, as the user won&amp;rsquo;t need the upload immediately.&lt;/p&gt;</description></item></channel></rss>