This article provides some concepts for improving the performance of .NET applications. This article assumes that you have a basic understanding of .NET and you have hands-on experience with project development. Basically, these guidelines have been provided by Microsoft's developers, I have just assembled them from various places.

It will be very useful if we follow them in our day-to-day work.

Manage memory efficiently

It is very important to manage memory very efficiently to improve the performance of applications. We need to keep in mind a few tips during application development.

Multithreading in application

Minimize thread creation and use the safe-tuning thread pool for multithreaded work. Avoid creating threads on a per–request basis; also avoid using Thread. Abort or Thread. Suspend.

Ensure that you appropriately tune the thread pool for ASP.NET applications and for Web Services.

Try to use an Asynchronous call

It's a new feature of C# 5.0. It may benefit client-side applications where you need to maintain user interface responsiveness. Those are the situations where we can use an asynchronous call as in the following:

Handle exception properly

Exception objects are one of the most resource-consuming objects in applications. So try to use them with enough care. We should not use an exception in regular application logic (sometimes people throw an exception at the time of validation, ensure that it's not happening in your application). Don't throw a new exception when you want to throw it across layers. Throwing a new exception consumes the same resources as a new exception. Just use throw one if you really want to throw it.

Don't forget to implement a finally in each try-catch block.

Choose string and StringBuilder in the right situation

It is recommended to choose StringBuilder when there is a need to perform a huge number of string concatenations. For small concatenation purposes, String performs well.

Choose the proper data type in an application

Arrays are the fastest of all collection types, so unless you need special functionalities like a dynamic extension of the collection, sorting, and searching, you should use arrays. If you need a collection type then choose the most appropriate type based on your functionality requirements to avoid performance penalties.

Improve performance of Serialization

Reduce the amount of data that is serialized by using XmlIgnore or NonSerialize attributes. To improve DataSet serialization, you can use column name aliasing, you can avoid serializing both the original and the updated data values, and you can reduce the number of DataTable instances that you serialize.

Reduce the working set size

A smaller working set produces better system performances. Fewer large assemblies rather than many smaller assemblies help reduce working-set size.

Manage the BLOB object with special care

Avoid moving Binary Large OBject (BLOB) data repeatedly, and consider storing pointers in the database to BLOB files that are maintained on the file system. Use Chunking to reduce the load in the server, and use chunking where network bandwidth is very limited. Use CommandBehaviour.SequencialAccess enumerator to stream BLOB data.

Try to use DataReader

Since nothing is faster than a DataReader, do not use a Dataset object when it is possible to use a DataReader object. DataReader is best if we want access forward-only read-only data and if we do not want to cache the data. Use a DataSet when you need to add flexibility to when you need to cache data between requests.

Conclusion

Those tips are very important to improve the performance of our applications. I hope you have understood all the concepts and you are very much interested in implementing them in your next application.