Skip to main content

Posts

Showing posts from June, 2019

Make .Net Web API queue requests operate 'single threaded'

Brief When working with a multithreading application it is very important for developers to handle multiple threads for a critical section of code. Monitor and lock is the way to provide thread safety in a multithreaded application in C#. Both provide a mechanism to ensure that only one thread is executing code at the same time to avoid any functional breaking of code. Example  Lock for only one request to be processed at a time. private static object s_SyncRoot = new object (); ... new Task (() => { lock ( s_SyncRoot ) { // process payment - single thread } }). Start (); return "ok" ; Links StackOverflow Monitor And Lock In C#

Fix Android WiFi Problem (Connecting and Disconnecting Wifi Frequntly)

Brief Some people have reported that they are facing WiFi connectivity issues on their newly updated Nexus. While some of them complained that their connection has significantly slowed down, some reported that the WiFi is completely broken. Here how you can fix both the issues. Here’s how to fix Android Nougat WiFi Problem. Solution 1:  First we try the oldest and simplest solution – restarting the device. This eliminates most of the underlying problems. After your device has finished booting, turn on the WiFi and it should work. If it doesn’t, keep reading. Solution 2:  Another simple trick includes rebooting your router. Most of the time the culprit is the router and turning it off and on again fixes the problem. Waiting about 5 minutes before turning the router on is recommended. Solution 3:  If you still have the problem, reconnecting to the WiFi might help. Remove the WiFi connection and reenter the password. Solution 4:  Last fix is to change the frequency of the Wi

LINQ Join with Multiple Conditions in On Clause in C#

Code First Approach: Here you go with: from b in _dbContext . Burden join bl in _dbContext . BurdenLookups on new { Organization_Type = b . Organization_Type_ID , Cost_Type = b . Cost_Type_ID } equals new { Organization_Type = bl . Organization_Type_ID , Cost_Type = bl . Cost_Type_ID } Second Approach You just need to name the anonymous property the same on both sides on new { t1 . ProjectID , SecondProperty = true } equals new { t2 . ProjectID , SecondProperty = t2 . Completed } into j1 Based on the comments of @svick, here is another implementation that might make more sense: from t1 in Projects from t2 in Tasks . Where ( x => t1 . ProjectID == x . ProjectID && x . Completed == true ) . DefaultIfEmpty () select new { t1 . ProjectName , t2 . TaskName } Link LINQ Join with Multiple Conditions in On Clause

Configuring DbContext in the .Net Core

Brief It is explained in the   Configuring a DbContext   section of the documentation: The   DbContextOptions   can be supplied to the   DbContext   by overriding the   OnConfiguring   method or externally via a constructor argument. If both are used,   OnConfiguring   is applied last and can overwrite options supplied to the constructor argument. In general, inside your   OnConfiguring   override you are supposed to check   DbContextOptionsBuilder.IsConfigured   property: Gets a value indicating whether any options have been configured. This can be useful when you have overridden   OnConfiguring   to configure the context, but in some cases you also externally provide options via the context constructor. This property can be used to determine if the options have already been set, and skip some or all of the logic in   OnConfiguring . Links MSDN StackOverflow

Why should I use IDisposable instead of using in c#?

Brief The answer given by "No One" is correct that using block can only be used for the classes that implement the IDisposable interface and explanation for it is perfect. The question from your side is "Why I need to add IDisposable on Test class and But on code review, I was asked to implement IDisposable interface and Finalizer methods on Test class." The answer is simple 1) As the per the coding standards followed by so many developers it is always good to implement IDisposable on the classes which use some resources and once the scope of that object is over the Dispose method in that class will make sure all the resources have been released. 2) The class that has been written is never such that in future no changes will be made and if such changes are made and new resources are added then the developer knows that he has to release those resources in Dispose function.  Refer link for details

Useful Links

Brief This page contains useful related to the Software Developer working in .Net technologies. https://stackoverflow.com/questions/17273021/windows-could-not-start-the-sql-server-mssqlserver-on-local-computer-error https://channel9.msdn.com/Shows/On-NET/Migrating-from-Entity-Framework-6-to-Core What's New in C# 8.0? Azure DevOps Projects Aps.net core connection strings Read From The Json File in Asp.net core EF Core  ADO.NET in .NET Core Reading data from json file in the .NET Core Create StudentMap.cs for Student.cs in EF Core Github “Updates were rejected because the remote contains work that you do not have” Readme.md file github, best way to write. Github - Basic writing and formatting syntax

async await Task in C#

Brief The Task asynchronous programming model (TAP) provides an abstraction over asynchronous code. You write code as a sequence of statements, just like always. You can read that code as though each statement completes before the next begins. The compiler performs a number of transformations because some of those statements may start work and return a   Task   that represents the ongoing work. Links Below are the links that might help you. MSDN YouTube (Basic) Youtube (Basic) Youtube (Advance)

Performance Check for Database Call C# before and after using AsParallel() (Not recommended for database call)

Brief Today we will discuss the performance check for the below things. OrderBy().ToList() : This is very slow. OrderBy().AsParallel().ToList(): This is very fast. AsParallel().OrderBy().ToList(): This is normal. Console Application Code is as below:     public static void Main()     {       const int m = 10000;       var s1 = Stopwatch.StartNew();       var students1 = context.Students.OrderBy(s => s.Name).ToList();       s1.Stop();       var s2 = Stopwatch.StartNew();       var students2 = context.Students.OrderBy(s => s.Name).AsParallel().ToList();       s2.Stop();       var s3 = Stopwatch.StartNew();       var students3 = context.Students.AsParallel().OrderBy(s => s.Name).ToList();       s3.Stop();       Console.WriteLine("Normal Fetch Time Students : " + ((double)(s1.Elapsed.TotalMilliseconds * 1000000) /           m).ToString("0.00 ns"));       Console.WriteLine("Order By Then AsParallel Fetch Time Students