Sunday, October 28, 2007

Care about Event Memory Leaks with Delegate.GetInvocationList()

Subscribed events are one of the most common reasons of memory leaks in .Net. This means that if you have an object that has an event

and there are other object that are subscribed to that event, the original object won't be properly disposed until all events are unsubscribed since

an event is a strong reference.

 ....

public partial class MyForm : Form
{
public event EventHandler OnDoMyFormThing;

public MyForm()
{
InitializeComponent();
}

private void button1_OnClick
{
MessageBox.Show(
"Test of OnDoMyFormThing event"
);
OnDoMyFormThing(this, new EventArgs());
}

protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
foreach (EventHandler eventDelegate
in
OnDoMyFormThing.GetInvocationList())
OnDoMyFormThing -= eventDelegate;
components.Dispose();
}
base.Dispose(disposing);
}
}



 


To full  article click here

Tuesday, October 23, 2007

Convert UTF-8 to Unicode

private static string Utf8ToUnicode(string utf8)
{
    return Encoding.Unicode.GetString(
        Encoding.Convert(
        Encoding.UTF8,
        Encoding.Unicode,
        Encoding.UTF8.GetBytes(utf8)));
 }

LINQ solution:
private static string Utf8ToUnicode(string utf8)
{
  return   Encoding.UTF8.
       GetString(input.Select(item => (byte)item).ToArray()); 
}

Strategy Pattern in C# 2.0

Strategy pattern can very handy when a system designer or architect wants to separate algorithms from the system implementation. Also with strategy pattern approach it is very easy to select between different algorithms on the fly. With the introduction of generics in .NET 2.0 implementing strategy pattern is even more easy.

Click Here

 

 

via DotNetKicks.com

Sunday, October 21, 2007

Full guide to create Installer class in VS.Net 2005

6 pages of amazing guide by devCity.net explains all point of deployment project and include follow parts:

  • Requirements 
  • Terminology
  • How to create an Installer Class
  • Un-written rules
  • Unpleasent features
  • Using these events (about Installer Class events)
  • Using the Commit event to change the target directory permissions.
  • Using the Uninstall event to clean the target directory
  • Where is the "NT AUTHORITY\SERVICE" account coming from?
  • Exceptions and Exception handling in your installer class.
  • Adding user interfaces (forms) to your installer class.
  • Launching your application after installation.
  • Conclusions.
  • References.

To read "Visual Studio 2005 Setup and Deployment Installer Classes and Custom Actions" CLICK HERE

kick it on DotNetKicks.com

Listas - new feature from Microsoft

At Live Labs, we are always experimenting with new ideas that we think will be useful.  Today we are releasing our latest technology preview:

Listas (http://listas.labs.live.com)

Listas is a tool for the creation, management and sharing of lists, notes, favorites, and more. It allows you to quickly and easily edit lists, share them with others for reading or wiki-style editing, and discover the public lists of other users.  We encourage you to try using it for meeting notes, bookmarks, shopping lists, to plan a night out, or whatever other creative ways you can think of....

kick it on DotNetKicks.com

Sunday, October 14, 2007

Sharp Cache Session Manager

The SharpCacheSessionManager is a HttpHandler that allows to display the entries stored in the Cache, Session and Application object. You can view the data stored inside the objects and you can also remove the objects from the corresponding storage. To download the SharpCacheSessionManager click HERE

via Christopher Steen

 kick it on DotNetKicks.com

Wednesday, October 10, 2007

Monday, October 08, 2007

Find and get list of controls on page

If you want to find list of controls on Page you can use this method:
private List<T> GetControls<T>() where T:Control
{
List<T> list = new List<T>();
foreach (Control rootControl in Controls)
{
foreach (Control control in rootControl.Controls)
{
if (control as T != null)
{
list.Add(control as T);
}
}
}
return list;
}
And a using is very simple. In example you can see how to change background to all labels:
List<Label> list = 
GetControls<Label>();
list.ForEach(
delegate (Label lab)
{
lab.BackColor =
System.Drawing.Color.Pink;
}
);

 


kick it on DotNetKicks.com

Sunday, October 07, 2007

A Visual Guide to Version Control

A beautiful, "highly visual" overview of Version Control, (a.k.a. Source Control). It also references Subversion command line examples, but the overview applies to most version control systems by BetterExplained.

To read a full article click HERE.