Posts

Showing posts from September, 2015

Explicitly freeing memory in c#

Recently I wrote a program which loads some CSV files in to DataTables and do some processing. These files are in large size and have nearly 1 million rows. When I load first file in to data table it works fine. But then I load the second file I get a “Out of Memory exception” even though first I make the previously loaded datatable to null. After searching for hours I found the following solution which solved my issue. var sourceDataTable = DataParserHelper .GetDataTableFromCsv( @"F:\FileSplitter\Data\5263\property_finance.csv" );                    sourceDataTable.Clear();           sourceDataTable.Dispose();           sourceDataTable = null ;                       GC .Collect();           GC .WaitForFullGCComplete();           GC .WaitForPendingFinalizers();   if you make the datatable null what happens is it frees the Datatable from the rows and columns. But actually those rows and columns retained in the memory and those are not ready for the garbage c

Sending Emails using SendGrid in C#.net

SendGrid has been built from the ground up as an API company. It is built to serve developers and make it easy to send email no matter your environment. You can send email over SMTP or HTTP, and even use one of it’s official client libraries. In just a few minutes, you can send your first email and millions more. It has different pricing plans for you , so you can select as you want. There is a free plan to which you can send up to 12,000 emails per month for free. For more details about pricing visit here 1. Create an account in SendGrid 2. Create a Console Application and add the following nuget package. SendGrid 5.1.0 3. Create a email template in SendGrid. 4. In the following example I’m loading some user information saved in a CSV file and then send password information for those users. Following is the template I have created for that in SendGrid. In the template I have used “{{}}” to specify the tags. You can use what ever the tab you want but make sure you use the same ta

Point in Time Restore in Azure SQL Database

Image
With new Basic, Standard and Premium Service Tiers , you get the new improved facility of “Point in Time Restore”. Which is, it provides you zero-cost automatic backup system. You only incur additional cost if you use the restore capability. The new database created by restore is charged at normal database rates. Together, the automated backup system and point-in-time restore provide a zero-cost, zero-admin way to protect databases from accidental corruption or deletion, whatever the cause. Period that backups retain will based on the service tier. Basic Tier :- 7 Days Standard Tier :- 14 Days Premium Tier :- 35 Days   Restoring a Live Database to a Point in Time Using Azure management portal you can easily. Go to the Database which you want to restore. Then Click on the “Restore” Button in the bottom bar. You will be prompted for a new database name and offered a slider control to pick the restore point within the retention period. Alternatively, you can manually enter the da

Calling Async Call from Main()

This is a small code which shows different ways of calling an async method inside Main Following is my sample method. public async Task < int >SampleMethod()      {          await Task .Delay(5000);          int answer = 21 * 2;          return answer;      }   1. Using  GetAwaiter()   static void Main( string [] args)      {          SampleMethod().GetAwaiter().OnCompleted(() => {      Console .WriteLine( "finished" ); });          Console .ReadKey();      }   2. Using  Wait() static void Main( string [] args)      {          SampleMethod().Wait();      }   Hope this helps,