<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[.NET voyage - Medium]]></title>
        <description><![CDATA[beautiful apps - Medium]]></description>
        <link>https://medium.com/net-voyage?source=rss----39c3022f32fd---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>.NET voyage - Medium</title>
            <link>https://medium.com/net-voyage?source=rss----39c3022f32fd---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 17:29:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/net-voyage" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Delegates , Events , Publishing , subscribing]]></title>
            <link>https://medium.com/net-voyage/delegates-events-publishing-subscribing-6fb441d5c92d?source=rss----39c3022f32fd---4</link>
            <guid isPermaLink="false">https://medium.com/p/6fb441d5c92d</guid>
            <dc:creator><![CDATA[ron naber]]></dc:creator>
            <pubDate>Mon, 03 Nov 2014 04:30:36 GMT</pubDate>
            <atom:updated>2014-11-03T04:30:35.975Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*iA7GFFTbeTzSHj0y17oxfw.jpeg" /></figure><p>this is something new I have tried here , all explanations are in comments. As they say in OOP , have smart coupling…</p><p>Just copy the below code in your visual studio :</p><p>using System;</p><p>using System.Collections.Generic;</p><p>using System.Linq;</p><p>using System.Text;</p><p>using System.Threading.Tasks;</p><p>using System.IO;</p><p>namespace _2112014</p><p>{</p><p>class Program</p><p>{</p><p>static void Main(string[] args)</p><p>{</p><p>#region Delegate,action</p><p>//multicast delegate example go to UseDelegate class to see implemenation</p><p>//UseDelegate UD = new UseDelegate(4, 5);</p><p>//calling action delegate , action delegate is kept outside function</p><p>//UseDelegate UD = new UseDelegate();</p><p>//UD.MyAction(5, 5);</p><p>#endregion</p><p>#region eventhandler example on filesystem</p><p>// event handler is delegate which sits between suscriber and publisher</p><p>// just mouse over the event -&gt; watcher.created above and see what kind of event handler it excepts</p><p>// check out the parameter</p><p>// and create same signature method in same class or other class and pass the method</p><p>//var watcher = new FileSystemWatcher(“C:\\Users\\rohan\\Desktop\\Event”);</p><p>//watcher.EnableRaisingEvents = true;</p><p>//watcher.Created += new FileSystemEventHandler(OnCreated);</p><p>//watcher.Deleted += OnDeleted;</p><p>//watcher.Changed += OnChanged;</p><p>#endregion</p><p>#region Event suscribing Car class event</p><p>//Car C = new Car(); //creating instance of that publisher class — Car</p><p>//C.change += ReturnWarningSign;//suscribing to event , telling if this event occurs then run this function</p><p>//C.pspeed = 89; //making the event fire</p><p>#endregion</p><p>// Console.ReadLine(); //so program doesnot close console screen</p><p>}</p><p>//public static void ReturnWarningSign() //fire this event when event occurs in publisher class</p><p>//{</p><p>// Console.WriteLine(“reduce speed”);</p><p>// Console.ReadLine();</p><p>//}</p><p>#region EventFunctions</p><p>private static void OnChanged(object sender, FileSystemEventArgs e)</p><p>{</p><p>Console.WriteLine(“{0} : {1} “, e.ChangeType, e.Name);</p><p>}</p><p>static void OnDeleted(object sender, FileSystemEventArgs e)</p><p>{</p><p>Console.WriteLine(“{0} : {1} “, e.ChangeType, e.Name);</p><p>}</p><p>static void OnCreated(object obj, FileSystemEventArgs e)</p><p>{</p><p>Console.WriteLine(“{0} : {1} “, e.ChangeType, e.Name);</p><p>}</p><p>#endregion</p><p>}</p><p>}</p><p><strong>same namespace</strong></p><p>using System;</p><p>using System.Collections.Generic;</p><p>using System.Linq;</p><p>using System.Text;</p><p>using System.Threading.Tasks;</p><p>namespace _2112014</p><p>{</p><p>public class UseDelegate</p><p>{</p><p>// TODO: Complete member initialization</p><p>//action and lamda expression</p><p>//action and func are types of delegates , action is used when you dont know exact signature</p><p>//action accepts 16 input parameters and no return types , while func can have return type</p><p>//lamda expression =&gt; is used to make functions on fly like below example , please study the syntax</p><p>public Action&lt;int, int&gt; MyAction = (int a, int b) =&gt; { Console.WriteLine(a + b); };</p><p>public UseDelegate()</p><p>{</p><p>}</p><p>public UseDelegate(int x , int y)</p><p>{</p><p>//creating multicast deligate — a deligate which contains more than one function</p><p>//# region mathematical function</p><p>Calculate MulticastCalculateDelegateObject = Add;</p><p>MulticastCalculateDelegateObject += Subtract;</p><p>MulticastCalculateDelegateObject += Divide;</p><p>MulticastCalculateDelegateObject += Multiply;</p><p>MulticastCalculateDelegateObject(x, y);</p><p>}</p><p>public delegate string Calculate(int x , int y);</p><p>#region MathematicalFunction</p><p>public string Add(int x, int y)</p><p>{</p><p>return ((x + y).ToString());</p><p>}</p><p>public string Multiply(int x, int y)</p><p>{</p><p>return ((x * y).ToString());</p><p>}</p><p>public string Divide(int x, int y)</p><p>{</p><p>return ((x / y).ToString());</p><p>}</p><p>public string Subtract(int x, int y)</p><p>{</p><p>return ((x — y).ToString());</p><p>}</p><p>#endregion</p><p>}</p><p>}</p><p>public class UseDelegate</p><p>{</p><p>// TODO: Complete member initialization</p><p>//action and lamda expression</p><p>//action and func are types of delegates , action is used when you dont know exact signature</p><p>//action accepts 16 input parameters and no return types , while func can have return type</p><p>//lamda expression =&gt; is used to make functions on fly like below example , please study the syntax</p><p>public Action&lt;int, int&gt; MyAction = (int a, int b) =&gt; { Console.WriteLine(a + b); };</p><p>public UseDelegate()</p><p>{</p><p>}</p><p>public UseDelegate(int x , int y)</p><p>{</p><p>//creating multicast deligate — a deligate which contains more than one function</p><p>//# region mathematical function</p><p>Calculate MulticastCalculateDelegateObject = Add;</p><p>MulticastCalculateDelegateObject += Subtract;</p><p>MulticastCalculateDelegateObject += Divide;</p><p>MulticastCalculateDelegateObject += Multiply;</p><p>MulticastCalculateDelegateObject(x, y);</p><p>}</p><p>public delegate string Calculate(int x , int y);</p><p>#region MathematicalFunction</p><p>public string Add(int x, int y)</p><p>{</p><p>return ((x + y).ToString());</p><p>}</p><p>public string Multiply(int x, int y)</p><p>{</p><p>return ((x * y).ToString());</p><p>}</p><p>public string Divide(int x, int y)</p><p>{</p><p>return ((x / y).ToString());</p><p>}</p><p>public string Subtract(int x, int y)</p><p>{</p><p>return ((x — y).ToString());</p><p>}</p><p>#endregion</p><p>}</p><p><strong>same namespace</strong></p><p>public class Car</p><p>{</p><p>public Car()</p><p>{</p><p>}</p><p>//created to learn about creating event , firing event , suscribing event to other class</p><p>//logic if speed greater than 50 then fire event</p><p>//declare an event</p><p>public event Action change;</p><p>private double speed;</p><p>public double pspeed</p><p>{</p><p>get {</p><p>return speed;</p><p>}</p><p>set { speed = value;</p><p>if (speed&gt;50)</p><p>{</p><p>if (change != null)</p><p>{</p><p>change(); //fire the event if the condition satisfies</p><p>}</p><p>}</p><p>}</p><p>}</p><p>}</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fb441d5c92d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/net-voyage/delegates-events-publishing-subscribing-6fb441d5c92d">Delegates , Events , Publishing , subscribing</a> was originally published in <a href="https://medium.com/net-voyage">.NET voyage</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Head scratching object oriented stuff]]></title>
            <link>https://medium.com/net-voyage/head-scratching-object-oriented-stuff-e17e11b2bce7?source=rss----39c3022f32fd---4</link>
            <guid isPermaLink="false">https://medium.com/p/e17e11b2bce7</guid>
            <dc:creator><![CDATA[ron naber]]></dc:creator>
            <pubDate>Tue, 28 Oct 2014 21:46:12 GMT</pubDate>
            <atom:updated>2014-10-28T22:10:50.215Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AkxKuR7oyvRVqD1QORtvVQ.jpeg" /></figure><p>some concepts which makes us nervous</p><h4>Last minute brush on classic object oriented questions</h4><h4>Abstract class :</h4><p>cannot be instantiated and acts as a base class for other classes.</p><p>common functionality that multiple derived classes can share and overrid</p><p>An abstract class contain abstract members as well as non-abstract members.</p><p>An abstract class can have concrete methods which is not possible in Interface.</p><p>An abstract class cannot be a sealed class because the sealed modifier<br>prevents a class from being inherited and the abstract modifier requires<br>a class to be inherited.</p><p>A non-abstract class which is derived from an abstract class must include<br>actual implementations of all the abstract members of parent abstract class.</p><p>An Abstract class can has access modifiers like private, protected,<br>internal with class members.But abstract members cannot have private<br>access modifier</p><p>An abstract class can have constructors and destructor.</p><p>Abstract class does not support multiple inheritance.</p><h4>little more about Abstract class :</h4><p>Abstract class cannot be instantiated and job of constructor is to get<br>called when child classes ‘s objects are created. So keeping the<br>constructor of abstract class as public gives idea to developer that<br>this class is instantiable , hence it should be protected or internal.<br>Again keeping constructor as private also doesnot make sense</p><h4>Lets see difference between const and readonly</h4><p>Yes thats not object oriented concept , but in implementation of this<br>two keywords object oriented concept plays important role.</p><p>Now const is compile time read.That means you dont need object to create<br>constant. So const value is initialised at compile time.</p><p>Const value is declared in compile time.</p><p>Read only is like const but IT IS INITIALISED AT RUN TIME.So at compile time<br>value of readonly variable is not known.</p><p>const are static while readonly is not. One way to put this is<br>that we dont have to create object of const to acess const but not the same<br>for readonly.</p><h4>What is singleton pattern ? and difference with static class</h4><p>Singleton pattern makes sure that you have only single instance of<br>that class available while static class can never be instantiated at all.</p><p>—single pattern has public class with private constructor<br>which means that no other class than that class can create object of that<br>class.<br>—then it has private instance class object declared in it as property.<br>—similarly you have public instance class object declared in it as property<br>— in the get method of public instance class object , we return the private instance after instantiating it.</p><p>using System;</p><p>public class Singleton<br>{ private static Singleton instance;</p><p>private Singleton() {}</p><p>public static Singleton Instance { get { if (instance == null) { instance = new Singleton(); } return instance; } }<br>}</p><p>also here you can declare a static method inside which we<br>can put constructor</p><p>and this static method can be called from any where.</p><h4>What if class implementing two interface have same methods</h4><p>we can do explicit implimentation then</p><p>public interface IFoo1<br>{ void DoStuff();<br>}</p><p>public interface IFoo2<br>{ void DoStuff();<br>}<br>You can implement both like this:</p><p>public class Foo : IFoo1, IFoo2<br>{ public void IFoo1.DoStuff() { }</p><p>public void IFoo2.DoStuff() { }<br>}</p><h4>Have a look at this perfect running code , this will tell us few more interesting things</h4><pre>class program<br>{<br> interface IA<br> {<br> void getName(string s);<br> }</pre><pre> interface IB<br> {<br> void getName(string s);<br> }</pre><pre> interface IC<br> {<br> void getName(string s);<br> }</pre><pre> public abstract class AC<br> {<br> public abstract void getName(string s);<br> }</pre><pre> public class CA : AC , IA, IB, IC<br> {<br> public override void getName(string s)<br> {<br> Console.WriteLine(s);<br> }<br> }</pre><pre> static void Main()<br> {<br> CA ca = new CA();</pre><pre> Console.ReadLine();<br> }</pre><pre>}</pre><p>so what is happening here is that 3 interface and one abstract method has same method getname . I used to think in such scenario we should implement method thrice (like implicit implementation in the above topic we discussed but voila , we dont need to and this is perfectly fine.</p><p>However lets keep in mind this thing</p><p>—to make interface happy just implement it</p><p>—to make abstract happy YOU HAVE TO OVERRIDE IT. At the end of the day dont forget that it is a class too.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e17e11b2bce7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/net-voyage/head-scratching-object-oriented-stuff-e17e11b2bce7">Head scratching object oriented stuff</a> was originally published in <a href="https://medium.com/net-voyage">.NET voyage</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[(Await +Async) and (task vs thread) :P]]></title>
            <link>https://medium.com/net-voyage/await-async-and-task-vs-thread-p-3b3d7adb4620?source=rss----39c3022f32fd---4</link>
            <guid isPermaLink="false">https://medium.com/p/3b3d7adb4620</guid>
            <dc:creator><![CDATA[ron naber]]></dc:creator>
            <pubDate>Mon, 27 Oct 2014 11:37:56 GMT</pubDate>
            <atom:updated>2014-10-27T11:37:55.945Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*JjWAJykgkUt8NvBF-S8XtA.jpeg" /><figcaption>when it gets difficult to understand just look at this relaxing picture and read again.Hope i can be of any help to you guys.</figcaption></figure><p>lets see so fun stuff</p><p><strong>Use of Async and Await in a real world problem</strong></p><p>while going through behind classes of ASP.NET mvc i found that async and await are used a lot.<br>i was not aware what is async and await.So i googled a bit and found out what kind of real world problems<br>this async and await solve.</p><p>Now there is an application in .NET which helps you to fetch information from three different database.<br>So when you click on “get info” button , there will be a blinker which will show busy sign till the time<br>information is received from all three sources.Once the information is received , the blinker will turn into<br>non busy sign.</p><p>Now before we go ahead we need to understand that when we create new task or thread function from our main thread,<br>the main thread will continue to do its work regardless what the new task is doing , so even if below code seems<br>to do job which we have coded it for — to run task 1 and then task 2 and then once both completed then print completed,<br>it will never reach completed status.At such time we use async and await</p><p><strong>without async and await</strong></p><p>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;<br>using System.Diagnostics;<br>using System.Threading;</p><p>namespace _26102014tasklibrary<br>{ class Program { static void Main(string[] args) {</p><p>Boolean IsBusy = true; Task task1 = new Task(new Action(SaySomething)); Task task2 = new Task(new Action(RunMillionIterations)); task1.Start(); if(task1.IsCompleted == true) { task2.Start(); } if(task1.IsCompleted==true &amp;&amp; task2.IsCompleted== true) { IsBusy = false; Console.WriteLine(“finished”); Console.ReadLine(); } else { Console.WriteLine(“finished”); Console.ReadLine(); } } public static void SaySomething() { for (int i = 0; i &lt;= 100000; i++) { Console.WriteLine(“this is how we roll”); } } public static void RunMillionIterations() { Stopwatch stp = new Stopwatch(); stp.Start(); for (int i = 0; i &lt;= 100000; i++) { Console.WriteLine(i); } stp.Stop(); TimeSpan ts = stp.Elapsed;</p><p>string elapsedTime = String.Format(“{0:00}:{1:00}:{2:00}.{3:00}”, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine(“RunTime “ + elapsedTime); }</p><p>}<br>}</p><p><strong>Now lets see how to add async and await to our code</strong></p><p>//remember async and await are like husband and wife.</p><p>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;<br>using System.Diagnostics;<br>using System.Threading;</p><p>namespace _26102014tasklibrary<br>{ class Program { Boolean Isbusy; static void Main(string[] args) { Newasyncmethod(); Console.ReadLine(); //Boolean IsBusy = true;</p><p>//Task task1 = new Task(new Action(SaySomething)); //Task task2 = new Task(new Action(RunMillionIterations));</p><p>//task1.Start(); //if(task1.IsCompleted == true) //{ // task2.Start(); //} //if(task1.IsCompleted==true &amp;&amp; task2.IsCompleted== true) //{ // IsBusy = false; // Console.WriteLine(“finished”); // Console.ReadLine(); //} //else //{ // Console.WriteLine(“finished”); // Console.ReadLine(); //} //Parallel.Invoke(() =&gt; SaySomething(), () =&gt; RunMillionIterations()); ////Thread O1 = new Thread(RunMillionIterations); ////O1.Start(); ////Parallel.For(0, 1, x =&gt; RunMillionIterations()); //Console.ReadLine(); }</p><p>public static async void Newasyncmethod() { await Task.Run(new Action(SaySomething)); await Task.Run(new Action(RunMillionIterations)); }</p><p>public static void SaySomething() { for (int i = 0; i &lt;= 100000; i++) { Console.WriteLine(“this is how we roll”); } } public static void RunMillionIterations() { Stopwatch stp = new Stopwatch(); stp.Start(); for (int i = 0; i &lt;= 100000; i++) { Console.WriteLine(i); } stp.Stop(); TimeSpan ts = stp.Elapsed;</p><p>string elapsedTime = String.Format(“{0:00}:{1:00}:{2:00}.{3:00}”, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine(“RunTime “ + elapsedTime); }</p><p>}<br>}</p><p>so what is happening here is , we are stopping main thread to go ahead till child thread has performed its function.<br>This is very useful when you face problems mentioned above.</p><p>or we can use the Task.WhenAll() function , which waits for both the tasks to finish to move ahead</p><p>spinner.IsBusy = true;<br>try<br>{ Task t1 = Task.Run(() =&gt; dataX = loadX()); Task t2 = Task.Run(() =&gt; dataY = loadY()); Task t3 = Task.Run(() =&gt; dataZ = loadZ());</p><p>await Task.WhenAll(t1, t2, t3);<br>}<br>finally<br>{ spinner.IsBusy = false;<br>}</p><p><strong>Tasks are upgrade from threads in c#</strong><br>They are features of 4.5 Net framework and benefits of using tasks ahead of thread are as follows</p><p>You can consider a Task as a more sophisticated version of a Thread. They are very easy to use and have a lot of advantages over Threads as follows:</p><p>You can <strong>create return types to Tasks</strong> as if they are functions.</p><p>You can the <strong>“ContinueWith” method</strong>, which will wait for the previous task and then start the execution. (Abstracting wait)</p><p>You can use Task.<strong>WaitAll</strong> and pass an array of tasks so you can wait till all tasks are complete.</p><p>You can attach task to the parent task, thus you can decide whether the parent or the child will exist first.</p><p>You can achieve data parallelism with LINQ queries.</p><p>You can create parallel for and foreach loops</p><p>Very easy to handle exceptions with tasks.</p><p>*Most important thing is if the same code is run on single core machine it will just act as a single process without any overhead of threads.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b3d7adb4620" width="1" height="1" alt=""><hr><p><a href="https://medium.com/net-voyage/await-async-and-task-vs-thread-p-3b3d7adb4620">(Await +Async) and (task vs thread) :P</a> was originally published in <a href="https://medium.com/net-voyage">.NET voyage</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Task parallel library]]></title>
            <link>https://medium.com/net-voyage/task-parallel-library-4d4ce9fe6b57?source=rss----39c3022f32fd---4</link>
            <guid isPermaLink="false">https://medium.com/p/4d4ce9fe6b57</guid>
            <dc:creator><![CDATA[ron naber]]></dc:creator>
            <pubDate>Sun, 26 Oct 2014 14:13:24 GMT</pubDate>
            <atom:updated>2014-10-27T09:47:13.950Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZvqRlyEvCjgmQb49vyVBPA.jpeg" /></figure><p>tutorial and small demo with code</p><p><strong>Why to use task parallel library</strong> — To improve performance of application by dividing the work between processors<br>equally.As hardware is improving ie more number of processor in servers , use of task will be very beneficial.</p><p>without task parallel library ( a feature of 4.5 Net framework ) , multiple threads are time sliced (context switched)</p><p><strong>example </strong>: suppose there are two threads running parallely , then thread 1 will run for lets say 20 seconds and then it<br>will give chance for thread 2 to run for 20 seconds . This is cycle but it can cut down performance of the application.</p><p>To check the performance of your application and analyse the distribution of processor when application is running ,<br>we will use tool called perfmon (performance monitor).It is very useful tool and easy to find too.Even if<br>you do not have this app , we could use stopwatch class of c# to find the timings.</p><p><strong>Without Task parallel library</strong></p><p>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;<br>using System.Diagnostics;<br>using System.Threading;</p><p>namespace _26102014tasklibrary<br>{ class Program { static void Main(string[] args) { Thread O1 = new Thread(RunMillionIterations); O1.Start(); Console.ReadLine(); }</p><p>public static void RunMillionIterations() { Stopwatch stp = new Stopwatch(); stp.Start(); for (int i = 0; i &lt;= 100000; i++) { Console.WriteLine(i); } stp.Stop(); TimeSpan ts = stp.Elapsed;</p><p>string elapsedTime = String.Format(“{0:00}:{1:00}:{2:00}.{3:00}”, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine(“RunTime “ + elapsedTime); }</p><p>}<br>}</p><p><strong>With Task parallel library</strong></p><p>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;<br>using System.Diagnostics;<br>using System.Threading;</p><p>namespace _26102014tasklibrary<br>{ class Program { static void Main(string[] args) { Parallel.For(0, 1, x =&gt; RunMillionIterations()); //we use parallel class to say that run this function in multiple processors Console.ReadLine(); }</p><p>public static void RunMillionIterations() { Stopwatch stp = new Stopwatch(); stp.Start(); for (int i = 0; i &lt;= 100000; i++) { Console.WriteLine(i); } stp.Stop(); TimeSpan ts = stp.Elapsed;</p><p>string elapsedTime = String.Format(“{0:00}:{1:00}:{2:00}.{3:00}”, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine(“RunTime “ + elapsedTime); }</p><p>}<br>}</p><p><strong>Time taken without Task parallel library</strong></p><p><strong>8 sec 36 milliseconds</strong></p><p><strong>Time take with Task parllel library</strong></p><p><strong>8 sec 29 milliseconds</strong></p><p>There are many more things to explore in task parallel library and its fun.</p><h4><strong>Now lets talk about Parallel method called Parallel.Invoke()</strong></h4><p>In simple words , Parallel.Invoke() methods accepts two types of parameters<br>They are 1) array of functions 2) two functions.</p><p>so what happens when you pass lets say two methods in Parallel.Invoke() method<br>The answer is the both the functions work simultaneosly in different cores saving time.<br>If you have two methods in your program which can run in parallel ,<br>lets say console.writeline() and a user created serialisetoxml() which can run parallel to each other<br>because neither affects each other , then why keep them in tetris mode (run console.writeline() first and then<br>go for serialisetoxml()) and waste time. Just run them in parallel.<br>Here in my example i have two methods which are not related to each other, hence i can introduce asynchronous<br>programming.Just try this program and see the output,<br>What you will find is that the time taken for both of them to complete<br>if they run individually one after the other is much more than if they run with parallelly.<br>Use can use the timer in the program to find time difference.<br>In my system it takes 12 seconds parallely and 28 seconds if in tetris mode.</p><p>using System;<br>using System.Collections.Generic;<br>using System.Linq;<br>using System.Text;<br>using System.Threading.Tasks;<br>using System.Diagnostics;<br>using System.Threading;</p><p>namespace _26102014tasklibrary<br>{ class Program { static void Main(string[] args) { Parallel.Invoke(() =&gt; SaySomething(), () =&gt; RunMillionIterations()); //Thread O1 = new Thread(RunMillionIterations); //O1.Start(); //Parallel.For(0, 1, x =&gt; RunMillionIterations()); Console.ReadLine(); } public static void SaySomething() { for (int i = 0; i &lt;= 100000; i++) { Console.WriteLine(“this is how we roll”); } } public static void RunMillionIterations() { Stopwatch stp = new Stopwatch(); stp.Start(); for (int i = 0; i &lt;= 100000; i++) { Console.WriteLine(i); } stp.Stop(); TimeSpan ts = stp.Elapsed;</p><p>string elapsedTime = String.Format(“{0:00}:{1:00}:{2:00}.{3:00}”, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine(“RunTime “ + elapsedTime); }</p><p>}<br>}</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d4ce9fe6b57" width="1" height="1" alt=""><hr><p><a href="https://medium.com/net-voyage/task-parallel-library-4d4ce9fe6b57">Task parallel library</a> was originally published in <a href="https://medium.com/net-voyage">.NET voyage</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[.NET Application Voyage pt 1]]></title>
            <link>https://medium.com/net-voyage/net-application-voyage-pt-1-abcc49cc3e28?source=rss----39c3022f32fd---4</link>
            <guid isPermaLink="false">https://medium.com/p/abcc49cc3e28</guid>
            <dc:creator><![CDATA[ron naber]]></dc:creator>
            <pubDate>Sat, 25 Oct 2014 14:30:17 GMT</pubDate>
            <atom:updated>2014-10-25T14:17:14.418Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*IqC4T4KwRj_lgvc8M1HRkA.jpeg" /></figure><p>corners,struggles,knowledge and fun</p><p><strong>Journey in the sea of .NET</strong></p><p><strong>Entity framework</strong></p><p><strong>Definition in 1 word :</strong></p><p>Entity Framework is an Object Relational Mapper (ORM).</p><p><strong>Little more definition :</strong></p><p>It basically generates business objects and entities according to the database tables and provides the mechanism for:<br>Performing basic CRUD (Create, Read, Update, Delete) operations.<br>Easily managing “1 to 1&quot;, “1 to many”, and “many to many” relationships.<br>Ability to have inheritance relationships between entities.</p><p><strong>Benefits :</strong></p><p>so major benefit is that we can code database in our c# code itself instead of having t-sql code.<br>another major benefit is type safety of code and fast execution.</p><p><strong>Why to use it again :</strong></p><p>Entity framework sits between your database and application , but does that mean that ado.net has become obsolete ?<br>No Entity framework uses ado.net but think of Entity framework as a tool which helps you use ado.net better.<br>Lets be honest who wants to use data reader and data set classes , i love entity framework.</p><p><strong>So what if you already have database of your application ? or you dont have database ?</strong></p><p>There are two ways you can work on Entity framework — Database first and Code first</p><p>If you already have database , you just have to create Entity model of that database (.Edmx file).</p><p>It copies all the mappings and tables and constraints to that model and viola within minutes you start working on your database.</p><p>I<strong>f you do not have database , then just code first and let entity framework create underlying classes for you.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abcc49cc3e28" width="1" height="1" alt=""><hr><p><a href="https://medium.com/net-voyage/net-application-voyage-pt-1-abcc49cc3e28">.NET Application Voyage pt 1</a> was originally published in <a href="https://medium.com/net-voyage">.NET voyage</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>