Velocity provides highly scalable distributed caching environment for Microsoft .net framework. By using Velocity, frequently used data can be stored in distributed cached environment for faster access and to avoid unnecessary calls to the database. Velocity also supports locking as well as automatic load balancing.
Velocity can be used for windows application or web application.
Velocity is provided in the form of a cluster. In this section I will cover what are all useful elements, how cluster works and some programming with velocity. Read more »
Suppose you have an application that needs to search for all occurrences of multiple strings in a text stream. For example, you might want to search a large text file for all occurrences of “cycling”, “bicycling”, “bicycle”, “cycle”, “bike”, and other bicycling-related terms. This can be a more difficult task than it first appears.
The simple case
If the file is small, the task isn’t terribly difficult. You can read the entire file as a string into memory and then use standard string searching methods to find each string, as shown here.
private static void FindAllSimple(string textToSearch, string[] searchStrings)
{
// brute force method
foreach (var s in searchStrings)
{
int iPos = 0;
int foundPos;
while (iPos < textToSearch.Length && (foundPos = textToSearch.IndexOf(s, iPos)) != -1)
{
Console.WriteLine(“{0},{1}”, foundPos, s);
iPos = foundPos + 1;
}
}
}
Read more »
Multithreading ensures that the program never “goes to sleep” by keeping UI more responsive to the user. In my blog I cover numbers of articles on multithreading programming, issues with multithreaded programming and the synchronization technique to handle these issues. I found it is worth to consolidate these all information at one place. Hopefully this will help visitor to quickly refer the topic.
What is Multithreading?
Article: Multithreading Read more »
ASP.Net, Best Practices, CSharp (C#), Threading
|
.Net, AutoResetEvent, C#, COM+ Synchronization, deadlocks, Interlocked, Issues of Multithreaded, livelocks, Lock Convoys, lock keyword, ManualResetEvent, MethodImplAttribute, Monitor class, Multithreading, Mutex, priority inversions, Race condition, ReaderWriterLock, Thread Synchronization, Two-Step Dances, Volatile Keyword, WaitHandle
In my previous articles “Issues with Multithreaded Programming: Part 1” and “Issues with Multithreaded Programming: Part 2” I have explained about four issues of Multithreading programming 1) Race Condition 2) DeadLock 3) LiveLock and 4) Priority Inversion. Continuing to my previous articles, in this article I have explained about following issues:
Best Practices, CSharp (C#), System Analysis and Design, Threading
|
DeadLock, Issues with Multithreaded Programming, Issues with Parallel Programming, LiveLock, Lock Convoys, Priority Inversion, Race condition, Two-Step Dances
In my previous article Issues with Multithreaded Programming : Part 1 I have explained about two most common issues of Multithreading programming 1) Race Condition and 2) DeadLock. Continuing to my previous article, in this article I have explained about following issues:
Best Practices, CSharp (C#), System Analysis and Design, Threading
|
DeadLock, Issues with Multithreaded Programming, Issues with Parallel Programming, LiveLock, Lock Convoys, Priority Inversion, Race condition, Two-Step Dances
Multithreaded (Parallel) programming is difficult for many reasons. Developer always has to put extra care to protect the program from issues like race condition, deadlocks, livelocks, priority inversions, two-step dances, and lock convoys. My personal experience says these all issues are tough to identify and then resolve.
It is always better to have understanding on these issues before writing multithreaded application. In this article I have covered the quick overview of following issues associated with multithreaded programming:
- Race condition
- DeadLock
- LiveLock
- Priority Inversion
- Two-Step Dances
- Lock Convoys Read more »
Best Practices, CSharp (C#), System Analysis and Design, Threading
|
DeadLock, Issues with Multithreaded Programming, Issues with Parallel Programming, LiveLock, Lock Convoys, Priority Inversion, Race condition, Two-Step Dances
Lambda expressions introduced in the C# 3.0. Lambda expressions help reducing the burden of writing Anonymous Methods. Before Anonymous Methods there was only way to declare the delegate was to use named method. Microsoft has put continues effort to reach to Lambda expressions:
- Before C# 2.0, named methods was the only option to declare the delegate
- C# 2.0 introduced the Anonymous methods.
- C# 3.0 and later, lambda expressions supersede anonymous methods as the preferred way to write inline code. There is only one case in which an anonymous method provides functionality not found in lambda expressions. Anonymous methods enable you to omit the parameter list. This means that an anonymous method can be converted to delegates with a variety of signatures. This is not possible with lambda expressions. Read more »
In my last article
LINQ to SQL Vs Entity Framework I discussed about how powerful the ADO.Net Entity Framework compare to LINQ2SQL. In this article I will discuss about how to create Database from Entity Model (Entity Framework).
While designing Database for a project, we normally first finalize the models (entities and the relationships) and then create the physical database in the database server. Entity Framework allows us to follow the same approach where we can create entities, build the relationship between entities, finalize the design of database and could also start coding using entities even if physically database is not exist. Once we are done with database modeling, we can create physical database from Model. So far, one item is missing from entity framework which is data, we still need database server to store the data. Hopefully Microsoft will come with something to provide kind of temporary storage where no database server is required for atleast for debugging purpose.
Read more »
LINQ to SQL and Entity Framework both are designed for ORM (Object Relational Model) support. They are developed to avoid the difficulties involved in writing Object Oriented code to perform RDMS operations. The OOP and RDMS are conceptually very different. The question arises when to use LINQ2SQL and when to use Entity Framework. What is the different between LINQ to SQL and Entity Framework.
LINQ to SQL and the Entity Framework have a lot in common, but each has features targeting different scenarios. While speaking about similarities or differences, I understand that ADO.NET Entity Framework’s LINQ to Entities can be considered as superset of LINQ to SQL and that, ADO.NET Entity Framework is much more than LINQ to Entities. Read more »
ASP.Net, Best Practices, CSharp (C#), System Analysis and Design
|
ADO.Net EF, C#, DotNet, EF, LINQ TO SQL, LINQ to SQL vs Entity Framework, LINQ2SQL, Object Relational Model, ORM
Today, one of my friends was asking me a question about how to add hyperlink text into the ListBox. I replied by adding respective control directly to the ListBox. Here in reply to my friend question, I am describing the steps:
Every Control in C#.net has a property called “Contorls” to add any control within it. I used the same to add LinkLable (Hyperlink text) to add into ListBox.
I have created one simple Windows Form application called “HyperLinkInListBox”. Added one windows form called “frmHyperLinkInListBox” and the following controls within the form:
- One ListBox control named “lstName” : this will display all the Names and will have hyperlink associated with it.
- One Label control “lblURL” : This will the URL associated with Name. So that when user will click on any Name in the ListBox, the respective URL will display here. Read more »
In my previous article I have explained about concurrent GC for workstation version of the CLR (Differences between Server and Workstation GC (types of garbage collection)). The CLR 4.0 has come with some performance enhancement (called “Background GC”) on the memory management process. This enhancement is majorly done with concurrent GC processing.
The Background GC came in picture because there was some latency issue with concurrent GC. Let me try to explain about the issue:
As you remember, Concurrent GC means the GC thread will run in parallel without blocking the application execution (well, not exactly the parallel – it was just minimize the blocking time). The concurrent GC operation can take some time if the memory allocation is quite large and this prevents short-lived (gen 0 and 1) collections while is running. Read more »
In my previous article (Garbage Collection – up to .Net Framework 3.5) I explained basic concept of GC. Here I am going deep to explain more about types of GC provided by CLR.
The CLR provides two types of garbage collection 1) Workstation garbage collection and 2) Server garbage collection.
Several times I have heard one common question in the community asking the differences between server and workstation GC, and how Concurrent GC fits in-between. Let me try to explain here:
Server GC: It is only available on multi-proc machines. It creates one GC heap (and thus one GC thread) for each processor, which are collected in parallel. This GC mode maximizes throughput (number of requests per second) and shows good scalability (performance really shines with 4 or more processors). Read more »
Here I am covering some basic information about how GC works in CLR. More detailed informations are covered @
The garbage collector is an automatic memory manager. It provides the following benefits:
- Enables us to develop the application without having to free memory.
- Allocates objects efficiently on the managed heap.
- Reclaims no longer used objects, clears their memory, and keeps the memory for future allocations.
- Provides memory safety by making sure that an object cannot use the content of another object. Read more »
Some days back one of my readers asking me a question about why one should migration from .net 1.1 to the latest framework. Here is the part of discussion:
Reader: Why the product should be migrated from .net Framework 1.1 to later framework if product is working as expected without any issue. What are different advantages (performance and system stability) regarding the upgrade to higher versions of the framework? What can be a good reason for the client to allow us to work on migration?
Me: Migrating existing .Net application developed using older version of .Net framework to the latest version is always worth considering, for many reasons. .Net application should be upgraded from time to time to the latest version of .Net to accrue the maximum benefits from technology advancement. Some of the reason/benefits are as follow: Read more »
An Abstract class without any implementation just looks like an Interface; however there are lot of differences than similarities between an Abstract class and an Interface. Let’s explain both concepts and compare their similarities and differences.
What is an Abstract Class?
An abstract class is a special kind of class that cannot be instantiated. So the question is why we need a class that cannot be instantiated? An abstract class is only to be sub-classed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.
What is an Interface?
An interface is not a class. It is an entity that is defined by the word Interface. An interface has no implementation; it only has the signature or in other words, just the definition of the methods without the body. As one of the similarities to Abstract class, it is a contract that is used to define hierarchies for all subclasses or it defines specific set of methods and their arguments. The main difference between them is that a class can implement more than one interface but can only inherit from one abstract class. Since C# doesn’t support multiple inheritance, interfaces are used to implement multiple inheritance.
Both Together
When we create an interface, we are basically creating a set of methods without any implementation that must be overridden by the implemented classes. The advantage is that it provides a way for a class to be a part of two classes: one from inheritance hierarchy and one from the interface.
When we create an abstract class, we are creating a base class that might have one or more completed methods but at least one or more methods are left uncompleted and declared abstract. If all the methods of an abstract class are uncompleted then it is same as an interface. The purpose of an abstract class is to provide a base class definition for how a set of derived classes will work and then allow the programmers to fill the implementation in the derived classes.
There are some similarities and differences between an interface and an abstract class that I have arranged in a table for easier comparison:
| Feature |
Interface |
Abstract class |
| Multiple inheritance |
A class may inherit several interfaces. |
A class may inherit only one abstract class. |
| Default implementation |
An interface cannot provide any code, just the signature. |
An abstract class can provide complete, default code and/or just the details that have to be overridden. |
| Access Modfiers |
An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public |
An abstract class can contain access modifiers for the subs, functions, properties |
| Core VS Peripheral |
Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovable interface. |
An abstract class defines the core identity of a class and there it is used for objects of the same type. |
| Homogeneity |
If various implementations only share method signatures then it is better to use Interfaces. |
If various implementations are of the same kind and use common behaviour or status then abstract class is better to use. |
| Speed |
Requires more time to find the actual method in the corresponding classes. |
Fast |
| Adding functionality (Versioning) |
If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method. |
If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly. |
| Fields and Constants |
No fields can be defined in interfaces |
An abstract class can have fields and constrants defined |
| Is-a vs able or can-do |
Interfaces are often used to describe the peripheral abilities of a class, not its central identity, e.g. an Automobile class might implement the Recyclable interface, which could apply to many otherwise totally unrelated objects. |
An abstract class defines the core identity of its descendants. If you defined a Dog abstract class then Damamation descendants are Dogs, they are not merely dogable. Implemented interfaces enumerate the general things a class can do, not the things a class is. |
| Homogeneity |
If all the various implementations share is the method signatures, then an interface works best. |
If the various implementations are all of a kind and share a common status and behavior, usually an abstract class works best. |
| Maintenance |
If your client code talks only in terms of an interface, you can easily change the concrete implementation behind it, using a factory method. |
Just like an interface, if your client code talks only in terms of an abstract class, you can easily change the concrete implementation behind it, using a factory method. |
| Adding functionality |
If you add a new method to an interface, you must track down all implementations of that interface in the universe and provide them with a concrete implementation of that method. |
If you add a new method to an abstract class, you have the option of providing a default implementation of it. Then all existing code will continue to work without change. |