<?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 Abid Zaidi on Medium]]></title>
        <description><![CDATA[Stories by Abid Zaidi on Medium]]></description>
        <link>https://medium.com/@abidzaidi?source=rss-27a92ad7f393------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*w-hxXy5woPKk3-tdzs_2yQ.png</url>
            <title>Stories by Abid Zaidi on Medium</title>
            <link>https://medium.com/@abidzaidi?source=rss-27a92ad7f393------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 22:24:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abidzaidi/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[Basics of Task Parallel Programming in .NET ]]></title>
            <link>https://medium.com/swlh/basics-of-task-parallel-programming-in-net-58c1474d5a54?source=rss-27a92ad7f393------2</link>
            <guid isPermaLink="false">https://medium.com/p/58c1474d5a54</guid>
            <dc:creator><![CDATA[Abid Zaidi]]></dc:creator>
            <pubDate>Wed, 05 Jun 2019 06:50:54 GMT</pubDate>
            <atom:updated>2019-06-06T19:36:43.793Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*muKxHoJfB0KNQELIODdgzg.png" /><figcaption>Multithreaded vs Single-threaded</figcaption></figure><h3>Task Parallel Library?!</h3><p>To take advantage of multicore systems programmers write parallel programs. These programs will solve problems by breaking them into small pieces and executing them in parallel or concurrently on multiple cores or processors. The legacy way of writing multithreaded programs in .NET is worker-oriented in which your program should be responsible for scheduling and management of threads. But with Task Parallel Library(TPL) things have been easier, its focus is task-oriented where focus is on what to do rather than how to do. TPL schedules threads on the thread pool and allows more functionality over the legacy threading techniques.</p><p>In this article, I will be going through the TPL in different yet basic aspects. I’ve created code gists on GitHub and linked them over here, I’m not going to write a very long explanation on what’s happening with the code but an overview would be sufficient. So lets kickstart with the basics!</p><h3>Different ways to create Tasks</h3><p>There are multiple ways to create a task, you may choose which suits you best. The simplest one is using the Factory’s static method. The rest of them create an instance of the Task class and call the Start method which is then passed to the task scheduler. (Few of the tasks call the printMessage Method which only consoles a message without returning anything)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/498e3a830e13f1d09a64a9ae4520eaae/href">https://medium.com/media/498e3a830e13f1d09a64a9ae4520eaae/href</a></iframe><h3>Setting Task States</h3><p>When there are many tasks and you need to give each task a separate identification, set the state by passing a costructor argument. You may also pass a variable of your choice and do computations with it. Capitalizing on the previous example following are a number of ways to set states while creating task instances.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dda3e4d5384b4b31c98c92e20a0eb318/href">https://medium.com/media/dda3e4d5384b4b31c98c92e20a0eb318/href</a></iframe><h3>Returning Result from a Task</h3><p>Tasks can return results in an asynchronous fashion. When Result property of Task is called it waits until the task is finished. In the following example, there are two tasks one is created using the task factory. The other task is an example using the anonymous method. Anonymous methods are the most common technique while calling task constructors.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e9d25cdd08d18f413d3690b4fcef208/href">https://medium.com/media/0e9d25cdd08d18f413d3690b4fcef208/href</a></iframe><h3>Canceling Tasks</h3><p>To cancel a task we need a CancellationToken which resides within a property of CancellationTokenSource, this token is then used as a constructor argument while creating Task instance. To Cancel a task simply call the Cancel() method on cancellation token source. The gist below shows how to cancel a task along with 3 different ways to go about monitoring your task after cancellation. In the first example Task is monitored by polling whether it has been cancelled or not. If it has we throw an exception which is addressed later on, in this article. The second example registers a delegate to monitor when the tasks get cancelled. In the third example WaitHandle.WaitOne() method is used which waits until the task has been cancelled. Go through the code below, it might take a while to sink in …</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e02ed5d110b272dc9da87aee2a9fe07/href">https://medium.com/media/0e02ed5d110b272dc9da87aee2a9fe07/href</a></iframe><h3>Composite Cancellation of Multiple Tasks</h3><p>Dependent tasks need to be cancelled together? quite easy to solve this when all tasks point to one cancellation source but when there are multiple cancellation sources you could simply link all the Cancellation Token sources to one composite source using the CreateLinkedTokenSource method which takes all sources as parameters. Whenever one of the sources are cancelled all tasks are cancelled together. Refer to the code which is a simplified version where i haven’t shown different task instances but i have shown how to link multiple token sources and monitoring the cancellation activity using waithandle’s WaitOne() method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77009d0967e94680a71ea0f91135395d/href">https://medium.com/media/77009d0967e94680a71ea0f91135395d/href</a></iframe><h3>Waiting for Tasks</h3><p>After the task is invoked there are few options on how to wait for them to complete. Individually you could call the Wait() method over a task instance which has a few overloads discussed in the gist below. Task class provides static methods that can wait on one or many tasks with WaitAny and WaitAll methods respectively.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8ee61d902aa15e17412efa203407fc4/href">https://medium.com/media/d8ee61d902aa15e17412efa203407fc4/href</a></iframe><h3>Handling Exceptions in Task</h3><p>On cancelling tasks we saw that an operation cancelled exception is thrown whenever the token source is cancelled. While calling Wait on all the task in a try catch block will catch all exceptions in Aggregate type. First example shows iterating through InnerExceptions property and accessing the details of each exception. Second example uses an iterative handler which can also be used to handle custom exceptions. A third alternate is to access Task properties mentioned in the end.</p><blockquote>Another way to handle an exception is using a custom escalation policy which can be done by adding an event handler on TaskScheduler.UnobservedTaskException</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/107e30c5992305355dd04fc3a918e665/href">https://medium.com/media/107e30c5992305355dd04fc3a918e665/href</a></iframe><h3>Lazy Task</h3><p>Lazy task is when you want to execute tasks in parallel only when the result is required. The lazy variable is not initialized until it is read, avoiding potentially expensive computing until they are needed or in some cases, avoiding work for variables that won’t be needed at all.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a8e849556137c6542227c6d2b4c988f/href">https://medium.com/media/3a8e849556137c6542227c6d2b4c988f/href</a></iframe><h3><strong>Thanks for reading 🙂</strong></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58c1474d5a54" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/basics-of-task-parallel-programming-in-net-58c1474d5a54">Basics of Task Parallel Programming in .NET 🧵</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Laptop table a DIY project ]]></title>
            <link>https://medium.com/@abidzaidi/laptop-table-a-diy-project-c81b901d5450?source=rss-27a92ad7f393------2</link>
            <guid isPermaLink="false">https://medium.com/p/c81b901d5450</guid>
            <category><![CDATA[woodworking]]></category>
            <category><![CDATA[laptop-tables]]></category>
            <category><![CDATA[interior-design]]></category>
            <category><![CDATA[diy]]></category>
            <dc:creator><![CDATA[Abid Zaidi]]></dc:creator>
            <pubDate>Sun, 24 Feb 2019 20:33:56 GMT</pubDate>
            <atom:updated>2019-02-24T20:33:56.711Z</atom:updated>
            <content:encoded><![CDATA[<p>As a software engineer in a 9–6 job I always manage to take some time out for learning but was never comfortable using my laptop with the space and surroundings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ggpeNZJM7AcW7gLfRNyXPQ.jpeg" /><figcaption>Laptop Table a DIY woodworking project</figcaption></figure><p>My observations were that I never had a proper place of sitting where I could keep my laptop and stay there for hours. During university times I always used to sit down on the headrest side of the bed and use my laptop and this posture wasn’t helping with my job routine as it made me sleep within an hour or so. The thought of having a proper table was obvious to struck my mind. I was never willing to go out on the streets and shop for a laptop table so i started to find one on the internet. After countless hours of searching and surfing on the web i had enough ideas to make it myself. I had done woodworking projects before and it seemed possible for what i had in my mind.</p><h4>Blueprinting the project</h4><p>Just before starting with the project i made a blueprint on paper, i guess drawing something on paper makes your vision more clearer especially when you are practically going to make it. The height and width of the table were major concerns. I wanted a table just enough to fit a laptop, mouse and few extras in the corner, so i decided to make the table <strong>26&quot; wide</strong>. For surface area I decided to keep the <strong>length 18&quot; </strong>which i think is ideal for a laptop. I chose <strong>30&quot; for height </strong>keeping in mind all computer chairs are adjustable and the height for a table is always dependent on the chair’s height. According to the blueprint I made, the total amount of wood needed was calculated as:</p><p><strong><em>(26&quot;x2)+22&quot;+(30&quot;x4)+24&quot;+(16&quot;x3)+(15&quot;x2) = 296&quot; = 24.6 ft.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1vS_8UAHNw_Q7j9mz-8DUg.gif" /><figcaption>Blueprint on sketchup</figcaption></figure><p><em>After completing this project i made a blueprint on sketchup (Not a hard tool if you love playing with shapes </em>😉)</p><h4>Timber Shopping and Preparation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tUN6MG5LwLKT4beWYsNNZA.jpeg" /></figure><p>I went to the timber shops near my house and bought 3 pieces of (2 x 1)sized wood planks almost 10 feet in length. I didn’t buy the 9&quot; plank as I already had a cutout piece which was just enough for my project. You could refer to these wood planks by ‘partal’ which is a common type of wood in Pakistan and easily available on any timber shop. Other items that I bought were 2&quot; nails (without head) and german glue for wood.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gFXwSjOKALbdmdaaPdKR5Q.jpeg" /><figcaption>Tools used for making a laptop table</figcaption></figure><p>With all the materials in hand I readied my tools which were nails, glue, inch tape, pencil, square ruler, hammer, nail plier, sanding paper, C Clamps, hacksaw, circular saw.</p><h4>How did I do it ?</h4><p>To start off i cut 2 pieces of 16&quot; and 2 pieces of 26&quot; from the 2x1 wood and made a square frame by gluing and nailing them together. After the base frame was ready I prepared the legs of the table from which each were 30&quot; long.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p9l6Co4ZvR7I1T1z0vRlqg.jpeg" /><figcaption>base frame and the legs of the laptop table</figcaption></figure><p>There was a weird technique i thought of before hammering the legs into the frame, having a 2x1(AxB) wood I thought to keep the front facing legs vertical (B faces forward) to the frame and the legs at the back attached horizontally (A faces forward). The reason behind this was to give myself more room in front as i would drag my chair inside the table. If i was unable to explain what I did, observe the picture below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7wu6lw7KPGS4oynRSCozlg.jpeg" /><figcaption>For the observant ones</figcaption></figure><p>All four legs joined an uneven, I now had to give them support from the bottom. It was obvious to leave the front side open for the chair to slide in, which leaves us with two sides and a back. 7 inches from the bottom i nailed the sides of the table which were of 15&quot; each and for the back I cut a 24&quot; piece and nailed it over the sides supporting over rear legs. The image below shows the current progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IpJ6amkEhRVYazhyfFJqGQ.jpeg" /><figcaption>Firm frame for the table</figcaption></figure><p>I couldn’t just wait to complete the top by glueing two pieces of 9&quot; together onto the frame, i used the circular saw to cut the 9&quot; plank resulting in two pieces from which each were 26.5&quot; long. I had cut the pieces 0.5&quot; longer because i wanted the top to be slightly larger than the frame and in reality the width of each piece was 9.25&quot; (which made the complete top 0.5&quot; wider than the top frame). I observed the top by placing it before gluing and realized that i had to add another support in between to make the top more strong and sturdy, so i cut a 16&quot; piece and quickly nailed it in middle and started to apply glue on the top frame. It was somehow hard to stick both pieces together onto the table, in order to achieve this C clamps were used, because I only had two of these some stone bricks were also placed above the 9&quot; boards to apply extra pressure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OpA4U5d4DsjmXaw7b2jgVw.jpeg" /></figure><p>I used the table for a couple of days then felt something was missing really bad, it was the leg rest..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cj5PZZOG9R_XiE08QQJWFA.jpeg" /></figure><p>So one of the final efforts was cutting a piece of less than 22&quot; and nail it in the bottom of the sides because I thought it was ideal there. Finally to add the cherry on top I did a little sanding on the each side to make it smooth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZXy9k94aG4fCNdGAnvhJjg.jpeg" /><figcaption>Final end product, Includes a leg rest in the middle which is ideal to the height of this chair</figcaption></figure><h4>Conclusively,</h4><p>There are a lot of improvements on the design, after using it for a couple of months I now think it could have been better if it was wider (probably 34&quot; rather than 26&quot;) and another thing is that I use the leg rest a lot and all the bottom supports are not on the same height makes it uncomfortable sometimes, although i can’t be sure on this thought of mine because i still haven’t bought a computer chair yet (I’m using a chair from an old dining table😔) .</p><p>Thank you for reading this article I thought to make it a ‘how-to’ which instead seems like a vlog of some sort. Feel free to discuss anything regarding woodworking, i’m a programmer by profession and no expert at woodworking but i’ve made a couple of projects like these.</p><p>Be sure to leave a clap and once again thanks.. 😊</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*aOwtdGbyiR_JLs7AzKNLwQ.gif" /><figcaption>Laptop Table DIY GIF</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c81b901d5450" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>