In my last tutorial on basics of threading, I explained what threading basically is and how it is actually implemented in C#. I would advise you to have a look at it before continuing with this article or if you have an Idea of what threads actually are, you can continue with this article. Writing a function and implementing a piece of code in it is not a big deal, anyone can write a function, pass it two variables add them and return back to the calling function. But in real world scenarios, where multiple tasks need to be performed simultaneously, this approach lacks sophistication and efficiency. This is why threading is so important because of threading comes with its ability to allow developers to write concurrent function which is more advanced form of functions which foster concurrency, Difference between Synchronous & Asynchronous Functions Before, dwelling into details of asynchronous functions, let us first differentiate between the synchronous and asynchronous... Read More →
Views: 73

Parallel Processing in Ruby using fork

In today's multitasking and multiprocessing environment it sometimes becomes necessary for programs to run certain tasks in parallel to be fast. Fork-ing provides just that. Fork is a system call which creates a clone of the process which first calls fork() and is called the parent process and the cloned process the child process, the return value of fork call helps each process determine whether they are a parent or a child. A more efficient solution to parallel processing are threads, but they need careful planning to be implemented as desired, but forking is easier to implement with a little more efficiency overhead than threads. In this Ruby article we'll be looking a creating child processes in Ruby and implementing simple parallel tasks with it, waiting for all child processes to finish and also checking exit status of the child processes. Forking in Ruby A code snippet says a lot more than words, so let's see a very simple snippet where we fork a child and print... Read More →
Views: 101

Advance Threading and Tasks in C#

In my last article, Complete Threading Tutorial in C#, I explained basics of threading. I explained that how threads can be created, how locking is implemented to make your applications thread-safe and how exception handling is implemented in threaded applications. This article explains some more advanced concepts. However, if you are not familiar with threads, I would advise you to first read my aforementioned article and then come to this article for advanced topics. Without wasting any further time, let us jump straight to the point.Foreground and Background Threads Thread Signaling Thread Pool Tasks Creating a Task Long Running Tasks Returning Values from Tasks Exception Handling With Tasks Task Continuation Foreground and Background Threads Threads which are created explicitly by the user are called foreground threads. The running time of the application is driven by the foreground threads and as long as any of these threads are executing, application keeps running. Background... Read More →
Views: 262

Complete Threading Tutorial (C#)

Often times, applications need to perform multiple tasks at a time. I always share Microsoft’s word processor’s example. While you type in the word processor, the application lets you type and in the meantime it is running spell-check and dictionary in the background to inform you whenever you type wrong spelling of a word. Basically multiple tasks are being done in a single program. This is the principle concurrency, to take advantage of multiprocessor hardware and to run multiple application parts simultaneously. Concurrency results in a more responsive application. Concurrency in .NET is implemented via threads. For now, you just need to keep in mind that tasks that take too much time should be run in a separate thread so that application can perform other important tasks meanwhile. Let us start with the most fundamental concept of concurrency i.e Threading.How to create a thread? Join & Sleep Thread IO Bound Operations vs. CPU Bound Operations Locking and Thread Safety Passing... Read More →
Views: 257
.NET Framework comes with a set of debugging tools. Particularly if you are using and advanced IDE such as Visual Studio, you can use debugger and other diagnostic tools available in the IDE. This debugging, however, is only applicable during the development of the application. Once the application is developed and shipped and then if an error occurs, it is not easy to diagnose and remove those errors via IDE debuggers. To handle such runtime application errors, special information is added with the code which can be later on used to diagnose and treat the error and bugs once the application is deployed. This chapter throws light on those techniques. Let us start this article with conditional compilation.Conditional Compilation Debug & Trace What are TraceListeners? Code Contracts Conditional Compilation Conditional compilation, as the name suggests, refers to the compilation of certain area of code based on some condition. Conditional compilation is done via preprocessor... Read More →
Views: 331

Disposal & Garbage Collection in C#

Garbage collection and memory management is probably that domain of programming where .NET Framework beats most of the other application development platforms. Most of the time, garbage collection is automatically done by .NET runtime once the object gets out of scope. When a .NET object is not being referenced by any module in the application, the garbage collector automatically disposes it after some time. However, this is not the case with all the objects. There are some objects that do not release resources implicitly and you have to incorporate a piece of code in your application to make them release resources. These objects include, open files, operating system handles, locks and unmanaged code. In .NET Framework, the process of explicitly releasing memory and resources is called disposal. The managed code is implicitly released and is referred as garbage collection. The simplest difference in garbage collection and disposal is that the former is done implicitly most of the... Read More →
Views: 318
XML documents are a standards described by World Wide Web Consortium (W3C) that are used for transferring information over the internet. The .NET Framework provides several namespaces and classes that allow developers to read, write and interact with the XML documents. In my article on LINQ to XML, I showed you that how types contained by System.Xml.Linq namespace can be used to interact with XML documents. However, there are many other types that can be used to read, write and communicate with the XML documents. In this article, we are going to see some of these types. XmlReader XmlWriter XmlDocument XmlReader XmlReader class belongs to System.Xml namespace and is used for reading XML stream in a forward-only manner. XmlReader is mostly used to read low-level streams. Without wasting any further time on theory, I am going to explain you that actually XmlReader reads from a file and from a string. Have a look at our first example for this tutorial. Example1 ... Read More →
Views: 550


XML stands for Extensible Markup language that is most commonly used for transferring information over the World Wide Web. XML documents are simple to write as well as understand both for humans as well as for software applications. If you come across an XML document, with little attention, you can point out that what this document is all about. However, this is not enough. You can have an XML document that contains thousands of lines of information. In such cases it is not advantageous to read and process the XML document manually as it might be time consuming as well as tedious. The real power of XML comes with its ability to be read by software applications. Since, XML documents follow some standards and if somehow software applications are tweaked to understand those standards, large XML documents can be seamlessly processed as done by human. This is the idea behind LINQ to XML. Luckily for developers, .NET Framework provides built-in capability to interact with XML documents... Read More →
Views: 332
LINQ is Microsoft’s latest data access technology. LINQ stands for language integrated query and it can be leverage to execute complex queries in a simple and more understandable manner. LINQ provides diverse query execution functions with the help of special methods that are known as query operators. In this article, we are going to throw light on some of the most important and useful query operators that can be used to perform almost all the routine data access tasks. If you are totally new to LINQ, you might need to look at our introductory articles on LINQ, particularly, Getting Started with LINQ and Interpreted LINQ queries. However, if you have basic knowledge of LINQ queries, and entity framework, you can continue reading this article. On the basis of input and output, the LINQ standard query operators can be broadly classified into three categories as follows:Sequence to sequence. (Takes input as sequence & gives output as sequence). Sequence to element. (Takes input as... Read More →
Views: 321
Entity framework is Microsoft’s latest data access technology and is considered a replacement for ADO.NET. However, there are still plenty of features where ADO.NET beats entity framework, but developers are now switching to Entity Framework owing to its strong decoupling and separation of concerns between the business and data access logic. This article is not focused towards explaining ins and outs of entity framework; this article explains that how LINQ can integrate with entity framework to achieve the desired data access feature. We will first start with our article by explaining how LINQ to SQL and then we will move towards LINQ to Entity framework. If you are not much familiar with foundations of LINQ, I would advise you to first have a look at my other tutorials on Getting Started with LINQ and Interpreted LINQ queries. Basically both LINQ to Entity Framework and LINQ to SQL are object-relational mappers on which LINQ queries can be executed. The major difference between... Read More →
Views: 444