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
A very simple scenario where client sends a request to server to perform certain action. There is no much data transfer between two parties – Probably no more than 50 bytes. We need to decide whether we go with Socket programming or use WCF (request-reply messaging pattern).
The analysis says: Read more »
Introduction
This article is about understanding the working concept of destructor in C#. I know you all may be thinking why a dedicated article on simple destructor phenomenon. As you read this article you will understand how different is C# destructor are when compared to C++ destructors.
In simple terms a destructor is a member that implements the actions required to destruct an instance of a class. The destructors enable the runtime system, to recover the heap space, to terminate file I/O that is associated with the removed class instance, or to perform both operations. For better understanding purpose I will compare C++ destructors with C# destructors. Read more »
In the early days of computing, a program would begin execution and then proceed through its steps until it completed. If the user was involved, the interaction was strictly controlled and limited to filling in fields.
Today’s Graphical User Interface (GUI) programming model requires a different approach, known as event-driven programming. A modern program presents the user interface and waits for the user to take an action. The user might take many different actions, such as choosing among menu selections, pushing buttons, updating text fields, clicking icons, and so forth. Each action causes an event to be raised. Other events can be raised without direct user action, such as events that correspond to timer ticks of the internal clock, email being received, file-copy operations completing, etc. In programming, you are often faced with situations where you need to execute a particular action, but you don’t know in advance which method, or even which object, you’ll want to call upon to execute it. For example, a button might know that it must notify some object when it is pushed, but it might not know which object or objects need to be notified.
C# adds on value to the often mentioned world of event driven programming by adding support through events and delegates. Read more »
Introduction
DotNet developers can free themselves from tedious memory management for their application as Microsoft Framework and CLR do it automatically.CLR provides a mechanism called as Garbage Collection which manages your applications memory. In this session we will discuss how garbage collector works and how it affects the performance of your Applications.
When you create an object using new () operator, the object’s memory is obtained from the managed heap. When the garbage collector decides that sufficient garbage has accumulated, it performs a collection to free some memory. This process is fully automatic, but there are a number of factors that you need to be aware of that can make the process more or less efficient. Read more »
Best Practices, CSharp (C#), System Analysis and Design
|
.Net, Dispose, Finalization, Garbage Collection, Garbage Collection Algorithm, Generations, Implement Dispose method, Performance, System.GC
In this article we will understand some of the concepts of object-oriented programming in C# like objects and classes. To read this article you must have C# programming basics.
Read more »
Introduction
The .NET CLR provides a common context within which all .NET applications execute, regardless of teh language in which they are written.CLR is responsible for handling every aspects of the managed code such as memory and resource management, secure environment to run in, garbage collection , access to the operating systems services etc. Code that targets the CLR is commonly known as managed code Read more »
CSharp (C#)
|
.Net, CLR, Code Execution, Compiling MSIL, Execution, Garbage Collection, interoperability, JIT, Just-in-Tim, Managed Code, Managed Execution Process, MSIL, resource management
Web form pages are HTTP-Based, they are stateless, which means they don’t know whether the requests are all from the same client, and pages are destroyed and recreated with each round trip to the server, therefore information will be lost, therefore state management is really an issue in developing web applications
We could easily solve these problems in ASP with cookie, query string, application, session and so on. Now in ASP.NET, we still can use these functions, but they are richer and more powerful, so let’s dive into it.
Mainly there are two different ways to manage web page’s state: Client-side and Server-side. Read more »
ASP.Net
|
.Net, Aplication object, Application state, ASP.Net, C#, Client-side state management, Cookies, Database, Hidden Field, Query Strings, Server side state management, Session object, Session state, SessionID, State Management, View State
Introduction:
When you install the Visual Studio .NET, the common language runtime has the Global Assembly Cache (GAC). The GAC stores assemblies that are shared by the several applications on the computer called as Shared Assembly or Global assembly. This shared assembly is globally available to all the applications on the computer.
Changing private assembly into a shared assembly:
A private assembly is normally used by a single application and is stored in a application directory or sub-directory beneath. This assembly cannot be shared by other applications. To make it globally available this assembly we need to install assembly in the global assembly cache (GAC). But to be installed in a GAC, it must have a Strong Name. Read more »
CSharp (C#)
|
.Net, .snk, Assembly, AssemblyKeyFile, C#, common language runtime, GAC, gacutil, Global Assembly Cache, private assembly, shared assembly, Strong Name
The ASP.NET request/response pipeline is a complex system. Patterns are used in the design of the pipeline itself and in the control architecture to effectively balance its performance with extensibility and ease of programming. Before delving into the pipeline, however, I’ll examine the patterns used in the programming model itself.
When dealing with collections of objects, there are often operations that are appropriate for both a single object and the entire collection. Think about an ASP.NET control. A control may be a simple single item like a Literal, or it could be composed of a complex collection of child controls, like a DataGrid is. Regardless, calling the Render method on either of these controls should still perform the same intuitive function.
When each item in the collection might itself contain collections of other objects, the use of the Composite pattern is appropriate. Composite is an easy way to represent tree-like collections without having to treat parent and leaf nodes differently.
The canonical example of Composite relies on an abstract base class, Component, that contains both methods for adding and removing children, and the operations common among parents and children. ASP.NET uses this formulation exactly with System.Web.UI.Control. Control represents the Component base class. It has operations for dealing with children (such as the child Controls property) as well as standard operations and properties like Render and Visible. Each object, whether a primitive object (like Literal) or a composite of several objects (like DataGrid), inherits from this base class.
Read more »
The easiest way to copy a file in a .NET program is to call the File.Copy method, supplying it the source and destination files. It could hardly be simpler than this:
File.Copy(srcFilename, destFilename);
That method will throw IOException if there is an existing file of the same name as destFilename. If you want to overwrite existing files, call the overload and specify true for the overwrite parameter:
File.Copy(srcFilename, destFilename, true);
File.Copy certainly is very easy to use, but as I mentioned in the previous section, it suffers from the large file copy problem. That is, using File.Copy to copy a very large file from one machine to another can cause the source machine to run out of memory. For example, I encountered that problem when executing a statement of this form:
File.Copy(@"\\server\data\file.dat", @"d:\data\file.dat", true);
If you want to copy a file and not encounter those problems, you have to write your own copy method. Read more »
Windows Server 2008 provides at least three different command line utilities for copying files. The familiar COPY and XCOPY commands have been around since the early DOS days. And ROBOCOPY, a more robust and feature-rich tool, began shipping with Windows Vista and Windows Server 2008. These tools work just fine in most cases. But all three suffer from a fatal flaw when you’re trying to copy a file that’s larger than available memory.
Manifestation of the Problem
Our main servers are quad-core machines with 32 gigabytes of RAM, running the 64 bit version of Windows Server 2008. Our custom format repository file is about 90 gigabytes in size. That’s after compression. In addition to daily backups, I periodically need to copy that file to another computer. And that’s where the problems start. Read more »
When a client requests an ASPX page from the Web server, the request travels through many steps before ultimately ending up as HTML displayed by the client’s browser. First, the request is processed by IIS and routed to the appropriate ISAPI extension. The ISAPI extension for ASP.NET (aspnet_isapi.dll) routes the request to the ASP.NET worker process.
At this point, the request begins to interact with classes that you are used to dealing with. The request is passed to an HttpApplication. Usually this is the class created in the codebehind file for Global.asax. The HttpApplication then passes the request through any number of HTTP Modules. These classes implement the IHttpModule interface and have a chance to modify the request (or even halt the processing of it) before it gets passed on to the next module. ASP.NET provides some standard modules which provide functionality you’re probably familiar with, including FormsAuthenticationModule, PassportAuthenticationModule, WindowsAuthenticationModule, and SessionStateModule, all of which provide exactly the functionality that their names imply.
Ultimately, the request ends up at an IHttpHandler, the most common of which is System.Web.UI.Page. Inside the IHttpHandler.ProcessRequest method, Page raises appropriate events (like Init, Load, and Render), handles ViewState, and provides the programming model for ASP.NET.
Read more »
Pre-compilation For Deployment
Pre-compilation for deployment creates an ‘executable’ (no source code) version of your web application. With pre-compilation for deployment you give the aspnet_compiler the path to your source code, and the path to a target directory for the compilation results, like below.
aspnet_compiler -p "C:\MyDevelopment\WebSite1" -v / C:\Staging
Read more »