Thought of the day

Posted in Uncategorized on January 19, 2010 by lovewithdotnet

Garbage Collector

Posted in C#.NET with tags on November 11, 2008 by lovewithdotnet

The .NET Framework’s garbage collector manages the allocation and release of memory for your application. Each time you use the new operator to create an object, the runtime allocates memory for the object from the managed heap. As long as address space is available in the managed heap, the runtime continues to allocate space for new objects. However, memory is not infinite. Eventually the garbage collector must perform a collection in order to free some memory. The garbage collector’s optimizing engine determines the best time to perform a collection,When the garbage collector performs a collection, it checks for objectsin the managed heap that are no longer being used by the application and performs the necessary operations to reclaim their memory.

Note:

Garbage collection is a CLR feature which automatically manages memory. Programmers forget to release the objects while coding .CLR automatically releases objects when they are no longer in use and refernced. CLR runs on non-deterministic to see the unused objects and cleans them. One side effect of this non-deterministic feature is that we cannot assume an object is destroyed when it goes out of the scope of a function.we should avoid using destructors because before GC destroys the object it first executes destructor in that case it will have to wait for code to release the umanaged resource. resultin in additional delays in GC. So its recommended to implement IDisposable interface and write cleaup code in Dispose method and call GC.SuppressFinalize method so instructing GC not to call your constructor.Certainly There  are more references and books by which you could visit . please check the given link: Microsoft Visual C# 2005 Step by Step Approach

Finalize

The following rules outline the usage guidelines for the Finalize method:

  • Only implement Finalize on objects that require finalization. There are performance costs associated with Finalize methods.
  • If you require a Finalize method, you should consider implementing IDisposable to allow users of your class to avoid the cost of invoking the Finalize method.
  • Do not make the Finalize method more visible. It should be protected, not public.
  • An object’s Finalize method should free any external resources that the object owns. Moreover, a Finalize method should release only resources that are held onto by the object. The Finalize method should not reference any other objects.
  • Do not directly call a Finalize method on an object other than the object’s base class. This is not a valid operation in the C# programming language.
  • Call the base.Finalize method from an object’s Finalize method.

Dispose

The following rules outline the usage guidelines for the Dispose method:

  • Implement the dispose design pattern on a type that encapsulates resources that explicitly need to be freed. Users can free external resources by calling the public Dispose method.
  • Implement the dispose design pattern on a base type that commonly has derived types that hold on to resources, even if the base type does not. If the base type has a close method, often this indicates the need to implement Dispose. In such cases, do not implement a Finalize method on the base type. Finalize should be implemented in any derived types that introduce resources that require cleanup.
  • Free any disposable resources a type owns in its Dispose method.
  • After Dispose has been called on an instance, prevent the Finalize method from running by calling the GC.SuppressFinalize Method. The exception to this rule is the rare situation in which work must be done in Finalize that is not covered by Dispose.
  • Call the base class’s Dispose method if it implements IDisposable.
  • Do not assume that Dispose will be called. Unmanaged resources owned by a type should also be released in a Finalize method in the event that Dispose is not called.

Stack n Queue In C# 2.0

Posted in C#.NET with tags on November 5, 2008 by lovewithdotnet

The System.Collections.Generic.Stack Class


The .NET Framework Base Class Library includes a Stack class in the Sytem.Collections.Generic namespace.
Like the Queue class, the Stack class maintains its elements internally using a circular array. The Stack class exposes its data through two methods: Push(item), which adds the passed-in item to the stack, and Pop(), which removes and returns the item at the top of the stack.

When a C# program is executed, the CLR maintains a call stack which, among other things, keeps track of the function invocations. Each time a function is called, its information is added to the call stack. Upon the function’s completion, the associated information is popped from the stack. The information at the top of the call stack represents the current function being executed.

The System.Collections.Generic.Stack Class


The .NET Framework Base Class Library provides the System.Collections.Generic.Queue class, which uses Generics to provide a type-safe Queue implementation.

Whereas our earlier code provided AddJob() and GetNextJob() methods, the Queue class provides identical functionality with its Enqueue(item) and Dequeue() methods, the Queue class maintain an internal circular array and two variables that serve as markers for the beginning and ending of the circular array: head and tail.

The Enqueue() method starts by determining if there is sufficient capacity for adding the new item to the queue. If so, it merely adds the element to the circular array at the tail index, and then “increments” tail using the modulus operator to ensure that tail does not exceed the internal array’s length.

The Dequeue() method returns the current element from the head index. It also sets the head index element to null and “increments” head. For those times where you may want to look at the head element, but not actually dequeue it, the Queue class also provides a Peek() method.

What is important to realize is that the Queue, unlike the List, does not allow random access.you cannot look at the third item in the queue without dequeing the first two items.the Queue class does have a Contains() method, so you can determine whether or not a specific item exists in the Queue. There’s also a ToArray() method that returns an array containing the Queue’s elements. CertainlyThere are more references and books by which you could visit . please check the given link: Microsoft Visual C# 2005 Step by Step Approach

Note: You may hear Queues referred to as FIFO data structures. FIFO stands for First In, First Out, and is synonymous to the processing order of first come, first served.

CLR: Common Language Runtime In C#

Posted in Dotnet Framework with tags on October 20, 2008 by lovewithdotnet

The .NET Framework has two main components: the common language runtime and the .NET Framework class library.

Code that you develop with a language compiler that targets the runtime is called managed code; it benefits from features such as cross-language integration, cross-language exception handling, enhanced security, versioning and deployment support, a simplified model for component interaction, and debugging and profiling services. There is one Most Profficient book by which you learn about CLR in C# enivronment.CLR via C#.net 2005

The runtime also enforces code robustness by implementing a strict type-and-code-verification infrastructure called the common type system (CTS). The CTS ensures that all managed code is self-describing

The runtime automatically handles object layout and manages references to objects, releasing them when they are no longer being used. This automatic memory management resolves the two most common application errors, memory leaks and invalid memory references.

The Very Basic Architecture of CLR is :

Source Code in specific Languages like (C#, VB,ASP) first goes to IL(Intermediate language) . And then this process first comes in Compile time and then after IL converts this Code in Native code using CLR (Common Language Runtime) in runtime.

Languages{C#, VB, Other Languages} -{C# compiler, VB Compiler}- MSIL Code -{CLR}- Native Code

 

IL

 

All .NET source code is compiled to IL. This IL is then converted to machine code at the point where the software is installed, or at run-time by a Just-In- Time (JIT) compiler.

Internet Explorer is an example of an unmanaged application that hosts the runtime (in the form of a MIME type extension). Using Internet Explorer to host the runtime enables you to embed managed components or Windows Forms controls in HTML documents. Hosting the runtime in this way makes managed mobile code (similar to Microsoft® ActiveX® controls) possible, but with significant improvements that only managed code can offer, such as semi-trusted execution and isolated file storage.

Generic

Posted in C#.NET on October 16, 2008 by lovewithdotnet

When we look at the term “generic”, unrelated to the programming world, it simply means something that is not tied to any sort of brand name

Generic in C#.net

By using a generic type parameter T you can write a single class that other client code can use without incurring the cost or risk of runtime casts or boxing operations. Certainly There  are more references and books by which you could visit . please check the given link: Microsoft Visual C# 2005 Step by Step Approach

Use generic types to maximize code reuse, type safety, and performance.

The most common use of generics is to create collection classes.

The .NET Framework class library contains several new generic collection classes in the System.Collections.Generic namespace. These should be used whenever possible in place of classes such as ArrayList in the System.Collections namespace.

You can create your own generic interfaces, classes, methods, events and delegates.

Generic classes may be constrained to enable access to methods on particular data types.

Information on the types used in a generic data type may be obtained at run-time by means of reflection.

 

Creating Our First Generic Type

public class Genric_Kartik<K>

{

private K k;

public K Kartik

{

get

{ return k; }

set

{k = value; }

}

}

And on button click I call my generic type, so it depends on you like where you want to assign a value for Ur generic type

 

protected void Button1_Click(object sender, EventArgs e)

{

Genric_Kartik<string> str = new Genric_Kartik<string>();

Genric_Kartik<int> str1 = new Genric_Kartik<int>();

str.Kartik = “HI REW”;

str1.Kartik = 23423;

Response.Write(str.Kartik);

Response.Write(str1.Kartik);

}

Generic Collections

Collection of a Type that we create, which we used to represent a GenricCollection in our system. Here is the definition for that class:

 

public class GenricCollection

{

protected string Myname;

protected int Myage;

public string MyName { get { return Myname; } set { Myname = value; } }

public int MyAge { get { return Myage; } set { Myage = value; } }

}

protected void Button1_Click(object sender, EventArgs e)

{

System.Collections.Generic.List<GenricCollection> Kartik = new System.Collections.Generic.List<GenricCollection>();

for (int x = 0; x < 5; x++)

{

GenricCollection GC = new GenricCollection();

GC.MyName = “The Sign OF Success !!”;

GC.MyAge = x;

Kartik.Add(GC);

Response.Write(GC.MyName);

Response.Write(GC.MyAge);

}

}

Passing Value from one page to another page

Posted in ASP.NET with tags on November 18, 2008 by lovewithdotnet

There is three more way to transfer value (rather then request.querystring or response.redirect) from one page to another…Check it out…

Default.aspx

These Code Written on Button Click

string str = txt.Text;

1) // By Context we could pass the value to one page to another

Context.Items.Add(“name”,str);

Server.Transfer(“JQueryPage.aspx”);

2) //By Session

Session["name"] = str;

3) //This is a new feature in asp.net2.0, In this term I went to the property of button and

set the postbackurl= “~/JQueryPage.aspx”

Then after I went to the JqueryPage and find the textbox control “txt” which I created in my root page so based on it I got my value directly

In the JqueryPage

We can Transfer Data From One Page to Another Page

JQueryPage.aspx

This code written on Page Load

1) // By Context

string sessionval = Context.Items["name"].ToString();

txt.Text = sessionval;

2) // This is By Session

string sessionval= Session["name"].ToString();

txt.Text = sessionval;

3) // By Previous PAge

TextBox txt1 = (TextBox)PreviousPage.FindControl(“txt”);

txt.Text = txt1.Text;

XAML : Extensible Application Markup Language.

Posted in Framework3.0 with tags , on October 22, 2008 by lovewithdotnet

Hi EveryBody,

Again new topic, here we have XAML. It is new for those who work for Dotnet Framework2.0. Microsoft launched Dotnet framework3.0 in 2006 and they relate with XAML with it. So will have a new idea to learn new thing.

You can think of it as HTML for Windows applications, but it is really quite a bit more expressive and powerful. For those of you code junkies out there, XAML is really no more than a special type of CLR object serialization. It was intentionally architected to serialize CLR object graphs into an XML representation that is both verbose and human readable. The reasoning behind this was to make it possible for developers to easily edit the markup by hand and enable the creation of powerful graphical tools that could generate markup for you behind the scenes.

When you compile an application that contains XAML files, the markup gets converted into BAML. BAML is a tokenized, binary representation of XAML. This binary representation is then stored inside the application’s resources and loaded as needed by WPF during the execution of your program. The main advantage of this approach is that you get a faster UI load time by reading a binary stream than through parsing XML.

HTML Fragment

<div style=“border: solid 5px black; margin: 10px; padding: 5px”> <input type=“button” value=“Click Me!” /> </div>

XAML Fragment

<Border BorderBrush=“Black” BorderThickness=“5″ Margin=“10″ Padding=“5″> <Button>Click Me!</Button> </Border>

Using XAML, you can represent a wide variety of UI related constructs. These include things like controls, layout panels, graphics primitives, 3D content and even animations.

BCL: Base Class Library

Posted in Dotnet Framework with tags on October 20, 2008 by lovewithdotnet

The Base Class Library (BCL) is a standard library available to all languages using the .NET Framework. .NET includes the BCL in order to encapsulate a large number of common functions, such as file reading and writing, graphic rendering, database interaction, and XML document manipulation.

The BCL generally serves as your main point of interaction with the runtime. There are many types of Base Class Library, Please find it below.A namespace is a logical grouping of types that perform related functions. Namespaces are logical groupings of related classes.

System

This namespace includes the core needs for programming. It includes base types like String, DateTime, Boolean, and so forth, support for environments such as the console, math functions, and base classes for attributes, exceptions, and arrays.

System.Collections

Defines many common containers or collections used in programming, such as lists, queues, stacks, hashtables, and dictionaries. It includes support for generics.

System. Configuration

Provides the infrastructure for handling configuration data

System. Transactions

Provides support for local or distributed transactions.

System.Text.RegularExpressions

This namespace includes regular expression support, for robust parsing and matching of string data

So with system namespace we have much class library by which we can relate to classes.

PageRequestManager Event

Posted in Ajax with tags on October 17, 2008 by lovewithdotnet

In Ajax Enabled asp.net life cycle some events helps to access the full page life cycle.

These event have many versatility because when application goes to load on server , this event helps to handle client page life cycle so there is some major features of PageRequestManager Events :-

PageRequestManager Events

The PageRequestManager class enables you to handle events in the client page life cycle and to provide custom event handlers that are specific to partial-page updates.

To use the PageRequestManager class in client script, you must put a ScriptManager server control on the Web page.

The EnablePartialRendering property of the ScriptManager control must be set to true (which is the default). When EnablePartialRendering is set to true, the client-script library that contains the PageRequestManager class is available in the page.

If the EnablePartialRendering property of the ScriptManager control is false, you cannot access the isInAsyncPostBack property because there is no PageRequestManager instance.

For synchronous postbacks, only the pageLoaded event is raised.

If you use the RegisterDataItem method of the ScriptManager control to send extra data during an asynchronous postback, you can access that data from the PageLoadingEventArgs, PageLoadedEventArgs, and EndRequestEventArgs objects.

Stopping and Canceling Asynchronous Postbacks

Two common tasks are to stop an asynchronous postback that is underway and to cancel a new request before it has begun. To perform these tasks, you do the following.

To stop an existing asynchronous postback, you call the abortPostback method of the PageRequestManager class.

To cancel a new asynchronous postback, you handle the initializeRequest event of the PageRequestManager class and set the cancel property to true.

Asp.net Enabled Ajax

Posted in Ajax on October 17, 2008 by lovewithdotnet

We all familiar with asp.net pages, but if we link it with Ajax, we will have question in our mind like what is Ajax. Ajax is Asynchronous JavaScript and XML so it’s a group of interrelated web development technique which gives a interactive web application and rich internet application.

AJAX features include client-script libraries that incorporate cross-browser ECMAScript (JavaScript)and dynamic HTML (DHTML) technologies, and integration with the ASP.NET server-based development platform.

AJAX-enabled applications offer:

Improved efficiency, because significant parts of a Web page’s processing are performed in the browser.

Familiar UI elements such as progress indicators, tooltips, and pop-up windows.

Partial-page updates that refresh only the parts of the Web page that have changed.

Client integration with ASP.NET application services for forms authentication, roles, and user profiles.

Auto-generated proxy classes that simplify calling Web service methods from client script.

A framework that lets you customize of server controls to include client capabilities.

Support for the most popular and generally used browsers, which includes Microsoft Internet Explorer,Mozilla Firefox, and Apple Safari

AJAX Server Architecture

Script Support

  1. You can also create custom client script for your ASP.NET applications. In that case, you can also use AJAX features to manage your custom script as static .js files (on disk) or as .js files embedded as resources in an assembly.

Script support for AJAX in ASP.NET is used to provide two important features:

The Microsoft AJAX Library, which is a type system and a set of JavaScript extensions that provide namespaces, inheritance, interfaces, enumerations, reflection, and additional features.

Partial-page rendering, which updates regions of the page by using an asynchronous postback

Localization

It provides additional support for localized .js files that are embedded in an assembly or that are provided on disk. ASP.NET can serve localized client scripts and resources automatically for specific languages and regions.

Web Services

With AJAX functionality in an ASP.NET Web page, you can use client script to call both ASP.NET Web services (.asmx) and Windows Communication Foundation (WCF) services (.svc).

Server Controls

When you add an AJAX control to an ASP.NET Web page, the page automatically sends supporting client script to the browser for AJAX functionality.

ScriptManager

Manages script resources for client components, partial-page rendering, localization, globalization, and custom user scripts.

UpdatePanel

Enables you to refresh selected parts of the page, instead of refreshing the whole page by using a synchronous postback.

UpdateProgress

Provides status information about partial-page updates in UpdatePanel controls.

The UpdateProgress control supports a DisplayAfter property that enables you to set a delay before the control is displayed. This prevents the control from flashing in the browser if the update occurs very fast. By default, the delay is set to 500 milliseconds (.5 second), meaning that the UpdateProgress control will not be displayed if the update takes less than half a second.

Timer

Performs postbacks at defined intervals. You can use the Timer control to post the whole page, or use it together with the UpdatePanel control to perform partial-page updates at a defined interval

ASP.NET PageRequestManager Class Overview

The PageRequestManager class in the Microsoft AJAX Library manages partial-page updates in the browse

The PageRequestManager class enables you to give precedence to a specific postback and cancel others that are underway.

How can I relate with XML using SQL??

Posted in XML on October 16, 2008 by lovewithdotnet

Hi Everybody,

A new thing in the Sql Server. i am going to explain the use of xml using sql server.

we have certain methods by which we can directly connect Sql Server to Xml Schema

suppose i have my xml tags -

<myname>

<test id=”1″ name=”Kartik”/>

<test id=”2″ name=”Raj”/>

</myname>

i want to add this xml tags in Sql, so for that i will use sp_xml_preparedocument

this System Defined Stored procedure will create xml Document and then i can get th output

declare @i int

exec sp_xml_preparedocument @i output,

‘<myname>

<test id=”1″ name=”Kartik”/>

<test id=”2″ name=”Raj”/>

</myname>’

select id,name

from OpenXml(@i, ‘myname/test’,1)

with (id int, name nvarchar(30))

It will show my result like

1 Kartik

2 Raj

Follow

Get every new post delivered to your Inbox.