SlideShare a Scribd company logo
Tips and Tricks of Developing
.NET Application
Joni
Applied Technology Laboratories
Bina Nusantara University
Agenda
 General Best Practices
 ASP .NET Specific
 Windows Forms Specific
 Resources
General Best Practices
 Looping optimization
ArrayList list = new ArrayList();ArrayList list = new ArrayList();
for(int ifor(int i == 0; i0; i << list.Count; i++)list.Count; i++)
{{
MyObject o = (MyObject)list[i];MyObject o = (MyObject)list[i];
o.DoSomeWork();o.DoSomeWork();
}}
ArrayList list = new ArrayList();ArrayList list = new ArrayList();
MyObject oMyObject o = null;= null;
for(int ifor(int i == 00, n =, n = list.Count; ilist.Count; i << nn; i++); i++)
{{
o = (MyObject)list[i];o = (MyObject)list[i];
o.DoSomeWork();o.DoSomeWork();
}}
General Best Practices
 Use proper casting, avoid polymorphic call
String s = “Hello world”;String s = “Hello world”;
Session[“key”] = s;Session[“key”] = s;
……
String result = Session[“key”].ToString();String result = Session[“key”].ToString();
String s = “Hello world”;String s = “Hello world”;
Session[“key”] = s;Session[“key”] = s;
……
String result =String result = (string)(string)Session[“key”];Session[“key”];
General Best Practices
 Acquire, Execute, Release pattern
 Works with any IDisposable object
 Data access classes, streams, text readers and writers,
network classes, etc.
using (Resource res = new Resource()) {using (Resource res = new Resource()) {
res.DoWork();res.DoWork();
}}
Resource res = new Resource(...);Resource res = new Resource(...);
try {try {
res.DoWork();res.DoWork();
}}
finally {finally {
if (res != null) ((IDisposable)res).Dispose();if (res != null) ((IDisposable)res).Dispose();
}}
General Best Practices
static void Copy(string sourceName, string destName) {static void Copy(string sourceName, string destName) {
Stream input = File.OpenRead(sourceName);Stream input = File.OpenRead(sourceName);
Stream output = File.Create(destName);Stream output = File.Create(destName);
byte[] b = new byte[65536];byte[] b = new byte[65536];
int n;int n;
while ((n = input.Read(b, 0, b.Length)) != 0) {while ((n = input.Read(b, 0, b.Length)) != 0) {
output.Write(b, 0, n);output.Write(b, 0, n);
}}
output.Close();output.Close();
input.Close();input.Close();
}}
static void Copy(string sourceName, string destName) {static void Copy(string sourceName, string destName) {
Stream input = File.OpenRead(sourceName);Stream input = File.OpenRead(sourceName);
try {try {
Stream output = File.Create(destName);Stream output = File.Create(destName);
try {try {
byte[] b = new byte[65536];byte[] b = new byte[65536];
int n;int n;
while ((n = input.Read(b, 0, b.Length)) != 0) {while ((n = input.Read(b, 0, b.Length)) != 0) {
output.Write(b, 0, n);output.Write(b, 0, n);
}}
}}
finally {finally {
output.Close();output.Close();
}}
}}
finally {finally {
input.Close();input.Close();
}}
}}
static void Copy(string sourceName, string destName) {static void Copy(string sourceName, string destName) {
using (Stream input = File.OpenRead(sourceName))using (Stream input = File.OpenRead(sourceName))
using (Stream output = File.Create(destName)) {using (Stream output = File.Create(destName)) {
byte[] b = new byte[65536];byte[] b = new byte[65536];
int n;int n;
while ((n = input.Read(b, 0, b.Length)) != 0) {while ((n = input.Read(b, 0, b.Length)) != 0) {
output.Write(b, 0, n);output.Write(b, 0, n);
}}
}}
}}
 In time critical application, avoid using
‘foreach’
General Best Practices
public static void Main(string[] args) {public static void Main(string[] args) {
foreach (string s in args) Console.WriteLine(s);foreach (string s in args) Console.WriteLine(s);
}}
public static void Main(string[] args) {public static void Main(string[] args) {
for(int i = 0, n = args.Length; i < n; i++)for(int i = 0, n = args.Length; i < n; i++)
Console.WriteLine(args[i]);Console.WriteLine(args[i]);
}}
General Best Practices
public ArrayList GetList()public ArrayList GetList()
{{
ArrayList temp = new ArrayList();ArrayList temp = new ArrayList();
……
return temp;return temp;
}}
……
public void DoWpublic void DoWoork()rk()
{{
ArrayList list = new ArrayList();ArrayList list = new ArrayList();
list = GetList();list = GetList();
}}
 Avoid unnecessary object instantiation
public ArrayList GetList()public ArrayList GetList()
{{
ArrayList temp = new ArrayList();ArrayList temp = new ArrayList();
……
return temp;return temp;
}}
……
public void DoWork()public void DoWork()
{{
ArrayList list =ArrayList list = nullnull;;
list = GetList();list = GetList();
}}
public ArrayList GetList()public ArrayList GetList()
{{
ArrayList temp = new ArrayList();ArrayList temp = new ArrayList();
……
return temp;return temp;
}}
……
public void DoWork()public void DoWork()
{{
ArrayList list =ArrayList list = GetList()GetList();;
}}
General Best Practices
 Use StringBuilder for string manipulation
publicpublic stringstring ProcessLongText()ProcessLongText()
{{
string text = “How are you?”;string text = “How are you?”;
string s = text;string s = text;
for(int i = 0; i < 1000; i++)for(int i = 0; i < 1000; i++)
{{
s += text;s += text;
}}
return s;return s;
}}
public string ProcessLongText()public string ProcessLongText()
{{
string text = “How are you?”;string text = “How are you?”;
StringBuilder s = new StringBuilder(text);StringBuilder s = new StringBuilder(text);
for(int i = 0; i < 1000; i++)for(int i = 0; i < 1000; i++)
{{
s.Append(text);s.Append(text);
}}
return s.ToString();return s.ToString();
}}
General Best Practices
 Do not rely on exceptions in your code
try {try {
result = 100 / num;result = 100 / num;
}}
catch (Exception e) {catch (Exception e) {
result = 0;result = 0;
}}
if (num != 0)if (num != 0)
result = 100 / num;result = 100 / num;
elseelse
result = 0;result = 0;
General Best Practices
 Don’t reinvent the wheel, unless you are super
programmer, use existing class library
 Use Data Access Application Block for
accessing database
objectobject resultresult ==
SqlHelper.ExecuteScalar(connectionString,SqlHelper.ExecuteScalar(connectionString,
CommandType.StoredProcedure, spName, sqlParameters);CommandType.StoredProcedure, spName, sqlParameters);
ASP .NET Specific
 Disable ViewState if not used
 Use output cache to speed-up performance
 Disable SessionState if not used
 Avoid unnecessary round trips to the server
 Use Page.IsPostBack to avoid performing unnecessary
processing on a round trip
 Consider disabling AutoEventWireup for your application
<%@ OutputCache Duration=“60" VaryByParam="None" Shared="true" %><%@ OutputCache Duration=“60" VaryByParam="None" Shared="true" %>
<page enableSessionState="true|false|ReadOnly” /><page enableSessionState="true|false|ReadOnly” />
ASP .NET Specific
 Be sure to disable debug mode
 Avoid using DataBinder.Eval
<%# DataBinder.Eval(Container.DataItem, “myfield") %><%# DataBinder.Eval(Container.DataItem, “myfield") %>
<%#<%# ((DataRowView)Container.DataItem)[“myfield”].ToString()((DataRowView)Container.DataItem)[“myfield”].ToString() %>%>
<compilation defaultLanguage="c#"<compilation defaultLanguage="c#" debug=“debug=“falsefalse"" />/>
ASP .NET Specific
 Override method, instead of attaching delegate
to it
private void InitializeComponent()private void InitializeComponent()
{{
this.Load += new System.EventHandler(this.Page_Load);this.Load += new System.EventHandler(this.Page_Load);
}}
private void Page_Load(object sender, System.EventArgs e)private void Page_Load(object sender, System.EventArgs e)
{{
……
}}
protectedprotected overrideoverride voidvoid OnOnLoad(System.EventArgs e)Load(System.EventArgs e)
{{
……
}}
ASP .NET Specific
 Use IDataReader instead of DataSet
 Use Repeater instead of DataGrid (if possible)
 Use the HttpServerUtility.Transfer method to
redirect between pages in the same application
 Use early binding in Visual Basic .NET or
JScript code
<%@ Page Language="VB" Strict="true" %><%@ Page Language="VB" Strict="true" %>
Windows Forms Specific
 Use multithreading appropriately to make your
application more responsive
 Windows Forms uses the single-threaded apartment
(STA) model because Windows Forms is based on
native Win32 windows that are inherently apartment-
threaded. The STA model requires that any methods
on a control that need to be called from outside the
control's creation thread must be marshaled to
(executed on) the control's creation thread
Windows Forms Specific
if(this.InvokeRequired)if(this.InvokeRequired)
{{
this.Invoke(this.Invoke(
newnew EventHandler(this.DisableButton),EventHandler(this.DisableButton),
new object[] {new object[] { null, EventArgs.Emptynull, EventArgs.Empty }}
););
}}
Resources
http://www.asp.net/
http://www.gotdotnet.com/
http://www.microsoft.com/resources/practices/
developer.mspx

More Related Content

KEY
Invertible-syntax 入門
PDF
The Ring programming language version 1.8 book - Part 50 of 202
PPTX
What’s new in C# 6
PDF
Spring Data for KSDG 2012/09
PDF
Building Real Time Systems on MongoDB Using the Oplog at Stripe
TXT
Productaccess m
KEY
Metaprogramming in Haskell
KEY
Template Haskell とか
Invertible-syntax 入門
The Ring programming language version 1.8 book - Part 50 of 202
What’s new in C# 6
Spring Data for KSDG 2012/09
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Productaccess m
Metaprogramming in Haskell
Template Haskell とか

What's hot (20)

PDF
Python Performance 101
PDF
はじめてのGroovy
KEY
関数潮流(Function Tendency)
PDF
The Ring programming language version 1.8 book - Part 75 of 202
PDF
The Ring programming language version 1.7 book - Part 73 of 196
PPTX
GreenDao Introduction
PDF
The Ring programming language version 1.5.2 book - Part 44 of 181
PDF
JavaScript Proxy (ES6)
PDF
Google Guava - Core libraries for Java & Android
PPTX
Grails queries
PPTX
Introduzione a C#
PDF
New SPL Features in PHP 5.3
PDF
PDF
Building Real Time Systems on MongoDB Using the Oplog at Stripe
PDF
Jggug 2010 330 Grails 1.3 観察
KEY
Spl Not A Bridge Too Far phpNW09
PDF
Building Real Time Systems on MongoDB Using the Oplog at Stripe
PDF
ORMLite Android
PPTX
Mcs011 solved assignment by divya singh
PPTX
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
Python Performance 101
はじめてのGroovy
関数潮流(Function Tendency)
The Ring programming language version 1.8 book - Part 75 of 202
The Ring programming language version 1.7 book - Part 73 of 196
GreenDao Introduction
The Ring programming language version 1.5.2 book - Part 44 of 181
JavaScript Proxy (ES6)
Google Guava - Core libraries for Java & Android
Grails queries
Introduzione a C#
New SPL Features in PHP 5.3
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Jggug 2010 330 Grails 1.3 観察
Spl Not A Bridge Too Far phpNW09
Building Real Time Systems on MongoDB Using the Oplog at Stripe
ORMLite Android
Mcs011 solved assignment by divya singh
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
Ad

Similar to Tips and Tricks of Developing .NET Application (20)

PDF
Jason parsing
PDF
Refactoring to Macros with Clojure
DOC
CBSE Class XII Comp sc practical file
PDF
Elm: give it a try
PDF
TypeScript Introduction
PPTX
Java Generics
PDF
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
PDF
Scala vs Java 8 in a Java 8 World
PDF
Java programs
PPSX
What's New In C# 7
PDF
Imugi: Compiler made with Python
PPTX
C# 6 and 7 and Futures 20180607
PDF
OrderTest.javapublic class OrderTest {       Get an arra.pdf
PPT
SDC - Einführung in Scala
PDF
Java Unicode with Cool GUI Examples
PDF
Java Unicode with Live GUI Examples
ODP
Scala 2 + 2 > 4
PDF
Productive Programming in Groovy
PDF
The Ring programming language version 1.5.3 book - Part 54 of 184
PDF
The Ring programming language version 1.5.3 book - Part 44 of 184
Jason parsing
Refactoring to Macros with Clojure
CBSE Class XII Comp sc practical file
Elm: give it a try
TypeScript Introduction
Java Generics
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
Scala vs Java 8 in a Java 8 World
Java programs
What's New In C# 7
Imugi: Compiler made with Python
C# 6 and 7 and Futures 20180607
OrderTest.javapublic class OrderTest {       Get an arra.pdf
SDC - Einführung in Scala
Java Unicode with Cool GUI Examples
Java Unicode with Live GUI Examples
Scala 2 + 2 > 4
Productive Programming in Groovy
The Ring programming language version 1.5.3 book - Part 54 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184
Ad

More from Joni (13)

PPTX
ASP.NET Core の ​ パフォーマンスを支える ​ I/O Pipeline と Channel
PPTX
.NET Framework で ​C# 8って使える? ​YESとNO!
PPTX
.NET Core 3.0 で Blazor を使用した​フルスタック C# Web アプリ​の構築
PPTX
Fiddler 使ってますか?
PPTX
Fukuoka.NET Conf 2018: 挑み続ける!Dockerコンテナによる ASP.NET Core アプリケーション開発事例
PPTX
ASP.NET パフォーマンス改善
PPT
Introduction to .NET
PPT
Introduction to Html
PPT
C#
PPT
Asp #1
PPT
Introduction to ASP.NET
PPT
Asp #2
PPTX
ASP.NET MVCはNullReferenceExceptionを潰している件
ASP.NET Core の ​ パフォーマンスを支える ​ I/O Pipeline と Channel
.NET Framework で ​C# 8って使える? ​YESとNO!
.NET Core 3.0 で Blazor を使用した​フルスタック C# Web アプリ​の構築
Fiddler 使ってますか?
Fukuoka.NET Conf 2018: 挑み続ける!Dockerコンテナによる ASP.NET Core アプリケーション開発事例
ASP.NET パフォーマンス改善
Introduction to .NET
Introduction to Html
C#
Asp #1
Introduction to ASP.NET
Asp #2
ASP.NET MVCはNullReferenceExceptionを潰している件

Recently uploaded (20)

PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
AI in Product Development-omnex systems
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
System and Network Administration Chapter 2
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
medical staffing services at VALiNTRY
PPTX
CHAPTER 2 - PM Management and IT Context
How to Migrate SBCGlobal Email to Yahoo Easily
Internet Downloader Manager (IDM) Crack 6.42 Build 41
AI in Product Development-omnex systems
VVF-Customer-Presentation2025-Ver1.9.pptx
Odoo Companies in India – Driving Business Transformation.pdf
Operating system designcfffgfgggggggvggggggggg
System and Network Administration Chapter 2
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Design an Analysis of Algorithms II-SECS-1021-03
wealthsignaloriginal-com-DS-text-... (1).pdf
ai tools demonstartion for schools and inter college
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Upgrade and Innovation Strategies for SAP ERP Customers
Navsoft: AI-Powered Business Solutions & Custom Software Development
PTS Company Brochure 2025 (1).pdf.......
medical staffing services at VALiNTRY
CHAPTER 2 - PM Management and IT Context

Tips and Tricks of Developing .NET Application

  • 1. Tips and Tricks of Developing .NET Application Joni Applied Technology Laboratories Bina Nusantara University
  • 2. Agenda  General Best Practices  ASP .NET Specific  Windows Forms Specific  Resources
  • 3. General Best Practices  Looping optimization ArrayList list = new ArrayList();ArrayList list = new ArrayList(); for(int ifor(int i == 0; i0; i << list.Count; i++)list.Count; i++) {{ MyObject o = (MyObject)list[i];MyObject o = (MyObject)list[i]; o.DoSomeWork();o.DoSomeWork(); }} ArrayList list = new ArrayList();ArrayList list = new ArrayList(); MyObject oMyObject o = null;= null; for(int ifor(int i == 00, n =, n = list.Count; ilist.Count; i << nn; i++); i++) {{ o = (MyObject)list[i];o = (MyObject)list[i]; o.DoSomeWork();o.DoSomeWork(); }}
  • 4. General Best Practices  Use proper casting, avoid polymorphic call String s = “Hello world”;String s = “Hello world”; Session[“key”] = s;Session[“key”] = s; …… String result = Session[“key”].ToString();String result = Session[“key”].ToString(); String s = “Hello world”;String s = “Hello world”; Session[“key”] = s;Session[“key”] = s; …… String result =String result = (string)(string)Session[“key”];Session[“key”];
  • 5. General Best Practices  Acquire, Execute, Release pattern  Works with any IDisposable object  Data access classes, streams, text readers and writers, network classes, etc. using (Resource res = new Resource()) {using (Resource res = new Resource()) { res.DoWork();res.DoWork(); }} Resource res = new Resource(...);Resource res = new Resource(...); try {try { res.DoWork();res.DoWork(); }} finally {finally { if (res != null) ((IDisposable)res).Dispose();if (res != null) ((IDisposable)res).Dispose(); }}
  • 6. General Best Practices static void Copy(string sourceName, string destName) {static void Copy(string sourceName, string destName) { Stream input = File.OpenRead(sourceName);Stream input = File.OpenRead(sourceName); Stream output = File.Create(destName);Stream output = File.Create(destName); byte[] b = new byte[65536];byte[] b = new byte[65536]; int n;int n; while ((n = input.Read(b, 0, b.Length)) != 0) {while ((n = input.Read(b, 0, b.Length)) != 0) { output.Write(b, 0, n);output.Write(b, 0, n); }} output.Close();output.Close(); input.Close();input.Close(); }} static void Copy(string sourceName, string destName) {static void Copy(string sourceName, string destName) { Stream input = File.OpenRead(sourceName);Stream input = File.OpenRead(sourceName); try {try { Stream output = File.Create(destName);Stream output = File.Create(destName); try {try { byte[] b = new byte[65536];byte[] b = new byte[65536]; int n;int n; while ((n = input.Read(b, 0, b.Length)) != 0) {while ((n = input.Read(b, 0, b.Length)) != 0) { output.Write(b, 0, n);output.Write(b, 0, n); }} }} finally {finally { output.Close();output.Close(); }} }} finally {finally { input.Close();input.Close(); }} }} static void Copy(string sourceName, string destName) {static void Copy(string sourceName, string destName) { using (Stream input = File.OpenRead(sourceName))using (Stream input = File.OpenRead(sourceName)) using (Stream output = File.Create(destName)) {using (Stream output = File.Create(destName)) { byte[] b = new byte[65536];byte[] b = new byte[65536]; int n;int n; while ((n = input.Read(b, 0, b.Length)) != 0) {while ((n = input.Read(b, 0, b.Length)) != 0) { output.Write(b, 0, n);output.Write(b, 0, n); }} }} }}
  • 7.  In time critical application, avoid using ‘foreach’ General Best Practices public static void Main(string[] args) {public static void Main(string[] args) { foreach (string s in args) Console.WriteLine(s);foreach (string s in args) Console.WriteLine(s); }} public static void Main(string[] args) {public static void Main(string[] args) { for(int i = 0, n = args.Length; i < n; i++)for(int i = 0, n = args.Length; i < n; i++) Console.WriteLine(args[i]);Console.WriteLine(args[i]); }}
  • 8. General Best Practices public ArrayList GetList()public ArrayList GetList() {{ ArrayList temp = new ArrayList();ArrayList temp = new ArrayList(); …… return temp;return temp; }} …… public void DoWpublic void DoWoork()rk() {{ ArrayList list = new ArrayList();ArrayList list = new ArrayList(); list = GetList();list = GetList(); }}  Avoid unnecessary object instantiation public ArrayList GetList()public ArrayList GetList() {{ ArrayList temp = new ArrayList();ArrayList temp = new ArrayList(); …… return temp;return temp; }} …… public void DoWork()public void DoWork() {{ ArrayList list =ArrayList list = nullnull;; list = GetList();list = GetList(); }} public ArrayList GetList()public ArrayList GetList() {{ ArrayList temp = new ArrayList();ArrayList temp = new ArrayList(); …… return temp;return temp; }} …… public void DoWork()public void DoWork() {{ ArrayList list =ArrayList list = GetList()GetList();; }}
  • 9. General Best Practices  Use StringBuilder for string manipulation publicpublic stringstring ProcessLongText()ProcessLongText() {{ string text = “How are you?”;string text = “How are you?”; string s = text;string s = text; for(int i = 0; i < 1000; i++)for(int i = 0; i < 1000; i++) {{ s += text;s += text; }} return s;return s; }} public string ProcessLongText()public string ProcessLongText() {{ string text = “How are you?”;string text = “How are you?”; StringBuilder s = new StringBuilder(text);StringBuilder s = new StringBuilder(text); for(int i = 0; i < 1000; i++)for(int i = 0; i < 1000; i++) {{ s.Append(text);s.Append(text); }} return s.ToString();return s.ToString(); }}
  • 10. General Best Practices  Do not rely on exceptions in your code try {try { result = 100 / num;result = 100 / num; }} catch (Exception e) {catch (Exception e) { result = 0;result = 0; }} if (num != 0)if (num != 0) result = 100 / num;result = 100 / num; elseelse result = 0;result = 0;
  • 11. General Best Practices  Don’t reinvent the wheel, unless you are super programmer, use existing class library  Use Data Access Application Block for accessing database objectobject resultresult == SqlHelper.ExecuteScalar(connectionString,SqlHelper.ExecuteScalar(connectionString, CommandType.StoredProcedure, spName, sqlParameters);CommandType.StoredProcedure, spName, sqlParameters);
  • 12. ASP .NET Specific  Disable ViewState if not used  Use output cache to speed-up performance  Disable SessionState if not used  Avoid unnecessary round trips to the server  Use Page.IsPostBack to avoid performing unnecessary processing on a round trip  Consider disabling AutoEventWireup for your application <%@ OutputCache Duration=“60" VaryByParam="None" Shared="true" %><%@ OutputCache Duration=“60" VaryByParam="None" Shared="true" %> <page enableSessionState="true|false|ReadOnly” /><page enableSessionState="true|false|ReadOnly” />
  • 13. ASP .NET Specific  Be sure to disable debug mode  Avoid using DataBinder.Eval <%# DataBinder.Eval(Container.DataItem, “myfield") %><%# DataBinder.Eval(Container.DataItem, “myfield") %> <%#<%# ((DataRowView)Container.DataItem)[“myfield”].ToString()((DataRowView)Container.DataItem)[“myfield”].ToString() %>%> <compilation defaultLanguage="c#"<compilation defaultLanguage="c#" debug=“debug=“falsefalse"" />/>
  • 14. ASP .NET Specific  Override method, instead of attaching delegate to it private void InitializeComponent()private void InitializeComponent() {{ this.Load += new System.EventHandler(this.Page_Load);this.Load += new System.EventHandler(this.Page_Load); }} private void Page_Load(object sender, System.EventArgs e)private void Page_Load(object sender, System.EventArgs e) {{ …… }} protectedprotected overrideoverride voidvoid OnOnLoad(System.EventArgs e)Load(System.EventArgs e) {{ …… }}
  • 15. ASP .NET Specific  Use IDataReader instead of DataSet  Use Repeater instead of DataGrid (if possible)  Use the HttpServerUtility.Transfer method to redirect between pages in the same application  Use early binding in Visual Basic .NET or JScript code <%@ Page Language="VB" Strict="true" %><%@ Page Language="VB" Strict="true" %>
  • 16. Windows Forms Specific  Use multithreading appropriately to make your application more responsive  Windows Forms uses the single-threaded apartment (STA) model because Windows Forms is based on native Win32 windows that are inherently apartment- threaded. The STA model requires that any methods on a control that need to be called from outside the control's creation thread must be marshaled to (executed on) the control's creation thread
  • 17. Windows Forms Specific if(this.InvokeRequired)if(this.InvokeRequired) {{ this.Invoke(this.Invoke( newnew EventHandler(this.DisableButton),EventHandler(this.DisableButton), new object[] {new object[] { null, EventArgs.Emptynull, EventArgs.Empty }} );); }}