Thursday, July 7, 2016

Optimize code using Threading

Threading is quite helpful to optimize the performance of programming  

Parallel code execution
Processor given sometimes to execute one function and then other function parallel
  • Thread.Sleep 
    • synchronous
    • when want to block the current thread 
    • this help to run as individual thread

  • Task.Delay
    • asynchronous
    • when want only to delay the current thread without blocking
    • this help to run multiple thread at once

Sample code:

  • Foreground thread
    • thread will keep on running even though the main application is quit 
  • Background thread
    •  all the thread die if the main application quit

using System.Threading;
using System.Threading.Task;

//Create thread
Thread obj1 = new Thread(Function1);
Thread obj2 = new Thread(Function2);

//Specially for background thread 
obj1.IsBackground = true;

//Invoke thread

static void Function1()
//do something 
//Wait 4 seconds



B' happiiiiiii always..............!

Wednesday, March 23, 2016

C#6 comes with new features..

Final version of C# 6 having been released, with couple of new features

  • Static Using Syntax
static qualifiers can be use as a namespace reference

  • Auto-Property Initializers

ability property inline initialization rather that and initialized through constructor

  • Dictionary Initializers & String Interpolation

cleaner way to  initialize the Dictionary and Concatenate strings together

  • NameOf Expression

handling exception with less codes

  • Expression Bodied Function & Property

functions and properties in lambda expressions save you from defining function and property statement block

  • Exception Filters

define specific catch block rather than specify a condition for a catch block

  • Await in a Catch and Finally Block

useful in log tracking without blocking, asynchronous code inside in a catch/finally block

  • Null Conditional Operator

released from NullReferenceException errors handeling


B' happiiiiiii always..............!