<?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[Stories by Shayan Kamalzadeh on Medium]]></title>
        <description><![CDATA[Stories by Shayan Kamalzadeh on Medium]]></description>
        <link>https://medium.com/@shayankamalzadeh?source=rss-e5d2d8f839eb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OdmMWUlBp3doUTOmCFGzTg.jpeg</url>
            <title>Stories by Shayan Kamalzadeh on Medium</title>
            <link>https://medium.com/@shayankamalzadeh?source=rss-e5d2d8f839eb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 20:00:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shayankamalzadeh/feed" 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 in C#: A Practical Approach to the Open/Closed Principle (OCP)]]></title>
            <link>https://shayankamalzadeh.medium.com/delegates-in-c-a-practical-approach-to-the-open-closed-principle-ocp-b28fe21b2c78?source=rss-e5d2d8f839eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/b28fe21b2c78</guid>
            <category><![CDATA[ocp]]></category>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[open-closed-principle]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[delegate]]></category>
            <dc:creator><![CDATA[Shayan Kamalzadeh]]></dc:creator>
            <pubDate>Tue, 18 Feb 2025 16:33:35 GMT</pubDate>
            <atom:updated>2025-02-18T16:33:35.857Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*UXwssRWjVrRmG1jXdtGUzA.png" /><figcaption>Delegate in c#</figcaption></figure><p>Hello my friends, Today I want to talk about Delegates in c#</p><p>I think most developers are familiar with the concept of delegates, so I do not want to talk about how it is defined, I want to talk about why it can be helpful especially in real applications(because we see always a lot of samples that it shows that delegates are useful for transfer methods (so what?)</p><p>one of reasons that I use delegates is OCP(open-close principle) .let me show you a sample without delegates:</p><pre>class PaymentProcessor<br>{<br>    public void ProcessPayment(string type, double amount)<br>    {<br>        if (type == &quot;CreditCard&quot;)<br>        {<br>            Console.WriteLine($&quot;Processing credit card payment of ${amount}&quot;);<br>        }<br>        else if (type == &quot;PayPal&quot;)<br>        {<br>            Console.WriteLine($&quot;Processing PayPal payment of ${amount}&quot;);<br>        }<br>        else if (type == &quot;BankTransfer&quot;)<br>        {<br>            Console.WriteLine($&quot;Processing bank transfer of ${amount}&quot;);<br>        }<br>        else<br>        {<br>            Console.WriteLine(&quot;Invalid payment type&quot;);<br>        }<br>    }<br>}<br><br>class Program<br>{<br>    static void Main()<br>    {<br>        PaymentProcessor processor = new PaymentProcessor();<br>        processor.ProcessPayment(&quot;CreditCard&quot;, 100);<br>        processor.ProcessPayment(&quot;PayPal&quot;, 200);<br>    }<br>}</pre><p>In this sample, we have a method that gets the type of payment and amount.</p><p>If you are familiar with SOLID you know it is against OCP. The first way (most of us use for refactoring it) is using an interface like this code:</p><pre>using System;<br><br>interface IPaymentMethod<br>{<br>    void Process(double amount);<br>}<br><br>class CreditCardPayment : IPaymentMethod<br>{<br>    public void Process(double amount)<br>    {<br>        Console.WriteLine($&quot;Processing credit card payment of ${amount}&quot;);<br>    }<br>}<br><br>class PayPalPayment : IPaymentMethod<br>{<br>    public void Process(double amount)<br>    {<br>        Console.WriteLine($&quot;Processing PayPal payment of ${amount}&quot;);<br>    }<br>}<br><br>class PaymentProcessor<br>{<br>    public void ProcessPayment(IPaymentMethod paymentMethod, double amount)<br>    {<br>        paymentMethod.Process(amount); <br>    }<br>}<br><br>class Program<br>{<br>    static void Main()<br>    {<br>        PaymentProcessor processor = new PaymentProcessor();<br><br>        processor.ProcessPayment(new CreditCardPayment(), 100);<br>        processor.ProcessPayment(new PayPalPayment(), 200);<br>    }<br>}</pre><h3><strong>Advantages of Using Interfaces</strong></h3><ol><li><strong>More structured and reusable</strong> — Each payment method is a concrete class that can have additional logic.</li><li><strong>Encapsulation</strong> — Each payment method handles its logic without exposing implementation details.</li><li><strong>Better for Dependency Injection (DI)</strong> — This can be easily used in <strong>loosely coupled</strong> architectures.</li><li><strong>More discoverable</strong> — Developers can easily find and extend payment methods if working in large teams.</li></ol><h3>Disadvantages of Interfaces</h3><ol><li><strong>More boilerplate code</strong> — Every new payment method needs a <strong>new class</strong>.</li><li><strong>Overkill for small cases</strong> — If you need to pass a simple function, creating a full class is unnecessary.</li><li><strong>Less flexibility</strong> — You <strong>must create an object</strong> instead of just passing a method.</li></ol><p>Now let me implement this approach with delegate:</p><pre>using System;<br><br>class PaymentProcessor<br>{<br>    public void ProcessPayment(Action&lt;double&gt; paymentMethod, double amount)<br>    {<br>        paymentMethod(amount); <br>    }<br>}<br><br>class Program<br>{<br>    static void CreditCardPayment(double amount)<br>    {<br>        Console.WriteLine($&quot;Processing credit card payment of ${amount}&quot;);<br>    }<br><br>    static void PayPalPayment(double amount)<br>    {<br>        Console.WriteLine($&quot;Processing PayPal payment of ${amount}&quot;);<br>    }<br><br>    static void Main()<br>    {<br>        PaymentProcessor processor = new PaymentProcessor();<br><br>        processor.ProcessPayment(CreditCardPayment, 100);  d<br>        processor.ProcessPayment(PayPalPayment, 200);<br>    }<br>}</pre><p>I used Action&lt;&gt;( It is a kind of delegate in c#).</p><h3>How Delegates Solve the Problem</h3><ol><li><strong>Removes Hardcoded Logic</strong>: No need to modify ProcessPayment when adding a new payment type.</li><li><strong>Extensible &amp; Maintainable</strong>: New payment methods can be added <strong>without modifying the existing class</strong>.</li><li><strong>Follows Open/Closed Principle</strong>: The method is open for extension but closed for modification.</li><li><strong>Flexible</strong>: The caller decides the method at runtime.</li></ol><h3>When Should You Use Delegates?</h3><p>Use delegates when:</p><ol><li>You want to allow <strong>custom behaviors without modifying existing code</strong>.</li><li>You are implementing <strong>event-driven programming</strong> (e.g., UI event handlers, and logging systems).</li><li>You want to <strong>decouple components</strong>, making code more <strong>maintainable and testable</strong>.</li></ol><h3><strong>In nutshell:</strong></h3><p>Using interface for big systems and using delegates for quick and dynamic behaviors. Using <strong>delegates</strong> in <strong>legacy code</strong> to achieve the <strong>Open/Closed Principle (OCP)</strong> is a <strong>great idea</strong> because it allows you to <strong>extend functionality without modifying existing code</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b28fe21b2c78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Async programming vs Parallel programming (Basic)]]></title>
            <link>https://shayankamalzadeh.medium.com/async-programming-vs-parallel-programming-basic-1a5e607fe22f?source=rss-e5d2d8f839eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a5e607fe22f</guid>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[parallel-programming]]></category>
            <category><![CDATA[async-programming]]></category>
            <category><![CDATA[async]]></category>
            <category><![CDATA[threads]]></category>
            <dc:creator><![CDATA[Shayan Kamalzadeh]]></dc:creator>
            <pubDate>Fri, 06 May 2022 08:20:43 GMT</pubDate>
            <atom:updated>2022-05-06T08:20:43.247Z</atom:updated>
            <content:encoded><![CDATA[<p>Today I want to talk about asynchronous programming. What is async programming and why is important? and what is the difference between async programming and parallel programming?</p><p>Imagine you have a computer with a CPU, Two processes, and a thread. threads inside each process.</p><p><strong>Question</strong>: What is the difference between <em>process </em>and <em>thread</em>?</p><p>when you start two different programs like the .net application, one program cannot access the memory of the second, so we have a kind of process isolation boundary. But the thread has another story: each process can have multiple threads and these threads can access all the memory of the entire process, therefore you can create a list of something and if you have 5 threads, these threads can all access the same list of something.</p><p>Now Imagine you have several processes and just 2 or 3 CPUs.Who is responsible for running all these processes.</p><p>Yes, the Operation system scheduler them. The processes are distributed across all the CPUs. and now thinking about a c# application that you wrote and it has some heavy calculation or doing some rendering with CPU like a game application or mathematical calculation. If you do that you typically split up your work into multiple independent units, you write the c# program, and these distribute the calculation problem into multiple parts, and you run them in parallel .therefore what we have for a certain amount of time in the CPU one, running certain thread let’s call it the thread one and at the same time you have on the CPU 2 running another thread(two) and at the end, you are maybe getting the resulting data, and transfer data to another thread for another CPU. This is <strong>Parallel programming</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tue2jjIWSxApCkz4ZK2KTg.png" /></figure><p><strong>Parallel programming</strong> means that you have some CPU-bound stuff that you would like to do really in parallel at the same point in time, multiple calculations are going on in your CPU. <strong>Be careful</strong> this is not <strong>Async programming.</strong></p><p>For Parallel programming, we need multiple CPU Cores, but for Async programming, we do not need multiple CPU Cores.</p><p>So we can think we have a CPU on our computer and run windows or WPF application. and our CPU has one thread for some part that we work this application, our thread is working and not idle, now imagine you won’t fetch a huge data from another server, so you send a request to the server and for example, a SQL engine in server start to fetch data, if you do not use async programming, our thread after sending a request to the server, waiting for a response and if you have just one thread like our scenario, your application freeze until getting a response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*alI1O57-2vc3kr5KrY1zlw.png" /></figure><p>As you can see in the above figure, my thread for 10 seconds was idle, and it is not good for our application. In async programming, when a thread sends a request for another server to get data, is freed and it can do other jobs and when data is prepared, a thread is responsible for bringing the data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a5e607fe22f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Equality Array(Data Structure tips in C#)]]></title>
            <link>https://shayankamalzadeh.medium.com/equality-array-data-structure-tips-in-c-bac313709c37?source=rss-e5d2d8f839eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/bac313709c37</guid>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Shayan Kamalzadeh]]></dc:creator>
            <pubDate>Mon, 18 Apr 2022 22:35:28 GMT</pubDate>
            <atom:updated>2022-04-18T22:35:28.546Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello guys, today I want to focus on Array, actually, I hope you know about array and in this article, I try to a bit deeper into it. so let&#39;s go…</p><p>I start with a sample:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*nz6TmdiQRbBNwoNHlvNTdw.jpeg" /><figcaption>define 2 DateTime array</figcaption></figure><p>I have defined exactly 2 DateTime arrays like each other, just the names are different.</p><p>What do you think? are they equal to each other?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*NC6rYpFXliHAj33TLjj_mg.jpeg" /></figure><p>As you see, when using the ‘==’ operator for 2 arrays, however, each item is exactly like the other, the result is false!</p><p>I hope you remember <em>Value-type</em> and <em>Referenc</em>e-<em>type</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JM3lal2M30P3dzrX1YjpeA.png" /></figure><p>When I define a value-Type like DateTime, each variable is put in memory like the above picture so “mydate!=yourdate”.Now let’s look at how Reference-Types are stored</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6z1akjKEB1DZwkGUl3p09Q.png" /></figure><p>Reference-Type means the variable doesn&#39;t actually contain the string ”Shayan” and stores the address of memory where store the variable(xx).</p><p>However DataTime is Value-Type,DataType[] is Referencetype because ,Array is Reference-Type</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-jDXJX5GVpJZlkPgpIzF5w.jpeg" /></figure><p>Therefore when defining 2 Arrays with the same values, they are located at different addresses, and bankHols1==bankHols2 is false (<strong>why???</strong>)</p><p>Because the “==” operator for ReferenceType check Addresses and addresses are different.</p><p>this rule is ok for all Reference-Type collections in c#, But be careful about “String”.</p><p>The string is reference type but Microsoft overrides the”==” operator for it so when using the “==” operator for 2 string that is the same as each other the result is true.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*wS5zCMLs2jrGLs5mzEkuNA.jpeg" /></figure><p>Now the question is: <strong><em>how can compare just the value of 2 arrays?</em></strong></p><p>Microsoft introduces the <strong>SequenceEqual()</strong> extension method (in the LinQ)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*gVR7JjgmyBMtb7RDPRISkQ.jpeg" /></figure><p>But be careful when using SequenceEqual(), it is too expensive because comparing each pair of elements if it is a bit large could be a lot of operations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bac313709c37" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Would you survive the Titanic?]]></title>
            <link>https://shayankamalzadeh.medium.com/would-you-survive-the-titanic-91ca7bb7be48?source=rss-e5d2d8f839eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/91ca7bb7be48</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[titanic]]></category>
            <dc:creator><![CDATA[Shayan Kamalzadeh]]></dc:creator>
            <pubDate>Sat, 09 Apr 2022 22:04:32 GMT</pubDate>
            <atom:updated>2022-04-09T22:04:32.447Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong><br>Analyze what kind of people are likely to survive. In particular, the use of machine learning tools to predict which passengers survived the Titanic<br>disaster. In fact, we have several features and two datasets, one is training and the other is testing. In this report, I try to investigate this issue and answer the following questions by using the logistic regression method, which is<br>fully described algorithms and Python codes in the machine learning classes.</p><p><strong>Training Model</strong></p><p>At this point for our training model with loss function look for the best rated learn and iteration number.<br>Using Train dataset for 100000 iterations. Depending on the result, the values in the thousandth range are better than the 10 thousandth range, so run the function again in a range (1e-3 and 4e-3) and you can see after approximately <strong>50000</strong> iterations, it converged at <strong>0.004</strong>(second figure)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*w5BwRBAN3Uwah6b1bwM7sg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*RnhlnirZzY_G6ZLGpCuhqw.png" /></figure><p><strong>Analyze our model</strong><br>After training, our model we obtain weight for all features and biases:<br><em>Class= -1.1468791 Sex= 2.80207082<br>Age= -0.03980783 Number Sibling= -0.32565276<br>Number Children= -0.09992111 Fare=0.00564653<br>Biases= 2.242518787043841</em><br>By observing the weights obtained, we can conclude that the higher class for the passenger, the lower the chance of survival (first-class passengers had more chance for survival than2end or third classes) because the value is<br>negative for class. The gender is positive therefore chance the of females was more than males (male =0 and female=1 in the dataset.) Age is negative, so young people had more chance of surviving The number of sibling and children are negative therefore who had fewer siblings and children<br>had a chance more of surviving(statistically) and Fare is positive and it shows that each person who buys a more expensive ticket had more chance of living. Another thing that we can understand in this model is two the biggest number is for class and sex therefore, we can guess most of the people who survived were female and were in the first classes. However, the weight of the sex<br>parameter is more than age but we must be careful about the range of these parameters (sex is just 0 and 1, age is more). We can see a scatter plot showing the distribution of the two classes in the plane defined by the two most influential features</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*LqvCpv7agT3sp7EnNOF6vg.png" /></figure><p>Yellow is the color of people who survive, and we can tell that most of the women who survived were from class 1 and most of the men who died were from class 3. On the other hand, in the chart below, almost no one was alive after 65 years.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*yiQ9Vqj_8_G9UjjYUOzBgg.png" /></figure><p>In the end, we check the accuracy of our model and the result is almost 80%</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*o_8E9nawBXbM2hoOjjfcrg.png" /></figure><p>After interpreting our model, we can predict the test dataset with the model.<br><strong>Evaluate the model</strong><br>By loading the experimental data set, model evaluation became possible. By keeping the threshold at 0.5, the test accuracy reached 78.5%. This value is a little less than the accuracy of the training, the model does not seem to have an overfitting or under-fitting problem, but to improve the model, I decided to<br>remove the features that weigh less and fit the model again. After removing features from the training dataset and calculating weight and biases age and using, them for test data set accuracy increased by 0.5 and obtain 79%</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91ca7bb7be48" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Entity Framework Tips(Part2)]]></title>
            <link>https://shayankamalzadeh.medium.com/entity-framework-tips-part2-e7ecfc355d53?source=rss-e5d2d8f839eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7ecfc355d53</guid>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[delete]]></category>
            <category><![CDATA[query-optimization]]></category>
            <category><![CDATA[entity-framework]]></category>
            <dc:creator><![CDATA[Shayan Kamalzadeh]]></dc:creator>
            <pubDate>Fri, 03 Sep 2021 10:25:08 GMT</pubDate>
            <atom:updated>2021-09-04T05:00:31.691Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m Shayan .Net developer, I’m going to talk about some simple tips that can help us to write a better query with EF.</p><p>In this part, I will talk about <strong>DELETE</strong>.</p><p>Let’s do it.</p><p>I have two classes that I want to use in the next parts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*IkxX4l6o5nzxAfgwd4tXew.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*bpQQ3-vHhiWccxZbvse37A.jpeg" /></figure><p>I want to delete a cat with ID 15</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*O4LXFz-KLsokN7nFwOZMTw.jpeg" /></figure><p>Therefore, first I find it and after that, I remove my object.</p><p>Run my SQL profiler:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*fRflt79pT-KMNyZJTVkxXA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*iNfZknjFb4zYl_cKptMkXA.jpeg" /></figure><p>Two queries run, first a select query after a delete query</p><p>Is it good? Absolutely not.</p><p>Why for each delete do we need a select query? It is awful.</p><p>Let&#39;s do it better:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*e0bA3Q5hFwPk2PAnc26YYg.jpeg" /></figure><p>I create an object from a cat and just set Id=16 and after that remove this object. without any finding</p><p>SQL profiler:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*P75ZnPabK3-C5BDBJXKVKw.jpeg" /></figure><p>Just run delete query.</p><p>OK, my dudes, this is the second tip .please <strong>follow </strong>me and I’m going to talk more about simple tips.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7ecfc355d53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Threadpool, Thread]]></title>
            <link>https://shayankamalzadeh.medium.com/hello-hello-today-i-want-talk-about-thread-threadpool-and-type-of-threads-in-net-aa2efc43c971?source=rss-e5d2d8f839eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa2efc43c971</guid>
            <dc:creator><![CDATA[Shayan Kamalzadeh]]></dc:creator>
            <pubDate>Mon, 22 Mar 2021 16:27:42 GMT</pubDate>
            <atom:updated>2021-03-23T05:46:35.298Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Threadpool, Thread</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lqUy-5YTXOBbxZp2nr0a6g.png" /></figure><p>Hello hello<br>Today I want to talk about Thread Threadpool and the type of Threads in .Net.</p><p><strong>What is a thread pool?</strong></p><p>Before talking about Threadpool, I have a question, Do you know about Thread??</p><p>So first let me talk about Thread.</p><p>A thread controls the flow of an executable program. By default, a program has one thread called Main <br>Thread. Main Thread starts when control enters in the Main method and it terminates when the Main method returns.</p><p>If the execution of a program is controlled by more than one thread, it’s called a Multithreaded<br>Application. Such a program increases the performance and response time of an application.</p><p>A thread can be created by using System.Threading.Thread class. A thread can only be manipulated on a method. For example, MainThread needs the Main method to control the flow of a program.</p><p><strong>Thread Pool</strong> <br>The cost of instantiating a managed thread is higher than reusing a free thread. In .NET, a thread pool is helpful to reuse the free threads. A thread pool is a collection of background threads created by a system and are available to perform any task when required. <br>When a program requires an extra thread, it is more efficient to use available free threads from a thread pool because it can save the cost of creating a thread. And when a thread completes its execution, it can go back to the thread pool so other programs can reuse the same thread again.</p><p><strong>Limitation of Thread Pool</strong> <br>• It is hard to tell when a thread of a thread pool has finished its execution. <br>• There is no “Start” method, so we cannot tell when a thread of a thread pool has started its execution because it is being managed by the system. <br>• It can’t manage a thread that returns a value.</p><p>As you see, I talked about the background thread.</p><p>We have two types of Thread, <strong>Background and Foreground Thread<br></strong>There are two kinds of threads in C#, i.e., Foreground thread and Background thread. By default, in C# all threads are initialized as foreground thread. An application cannot terminate its execution until all its foreground threads are completed. <br>A background thread is almost identical to a foreground thread. The one difference is that, if the Main Thread has completed its execution and the background thread is the only thread remaining in the application, the Main Thread will terminate the application and not wait for the background thread to be completed<strong>.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa2efc43c971" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>