The article emphasizes the importance of proper handling of disposable objects in .NET projects to avoid memory-related issues. It discusses the creation of "bulletproof" disposable types using extension methods, such as TryDispose() for local variables, DisposeFields() for managing disposable fields, and DisposeCollection() for handling disposable objects in collections. Additionally, the author recommends using a memory profiler, specifically ".NET Memory Profiler" by SciTech Software AB, to ensure there are no virtual memory leaks in the application before deployment.
Tag: Tip of the Day
Randomizing A Collection: One Time or Forever
Learn how to randomly choose items from a collection that can loop forever.
Combining URL Paths
If you are like me, then you need to combine a base url path with another path to a web page or a service. Since base paths change often due to the application running from different environments, this is a common task. The .NET Framework provided use with a simple way of combining file paths, … Continue reading Combining URL Paths
Creating an MD5 String Hash
Below is code that will easily hash a string using the MD5 encryption. This is typically used when performing data integrity checks. using System.Security.Cryptography; using System.Text; namespace MyApp.Caching { public static class CachingHelper { static public string CreateMD5Hash(string str) { var unicodeText = new byte[str.Length * 2]; Encoding.Unicode.GetEncoder().GetBytes(str.ToCharArray(), 0, … Continue reading Creating an MD5 String Hash
Converting Value Types
Converting a type like a string to an value type like integer, can easily cause an exception, which is a huge performance killer. Hopefully you have wrapped the conversion in a Try Catch block, if not your program could take a nose dive and your users will be upset. Consider the code below that converts … Continue reading Converting Value Types
Type Design: Equals and HashCode
Good type design dictates that the Equals should always be overridden. This is actually a FXCop violation but 99.99% of types that I see, never has it (or GetHashCode). Overriding Equals is pretty easy. Public Overloads Function Equals(ByVal obj As [Object] ) As Boolean Try Dim ci = DirectCast (obj, ComputerInfo ) Return (ci.OSFullName = … Continue reading Type Design: Equals and HashCode
Searching for Text Within a Stored Procedure
Here is a cool sp that will find any text within a stored procedure. Add this your Master database. CREATE PROCEDURE [dbo].[Find_text_in_sp] @text VARCHAR(250),@dbname VARCHAR(64) = NULL AS BEGIN SET nocount ON; IF @dbname IS NULL BEGIN --enumerate all databases. DECLARE #db CURSOR FOR SELECT name FROM MASTER..sysdatabases DECLARE @c_dbname VARCHAR(64) OPEN #db FETCH #db INTO @c_dbname WHILE @@FETCH_STATUS <> -1 --and @MyCount < 500 BEGIN EXECUTE Find_text_in_sp @text, @c_dbname FETCH #db INTO @c_dbname END CLOSE #db DEALLOCATE #db END --if @dbname is null ELSE BEGIN --@dbname is not null DECLARE @sql VARCHAR(250) --create the find like command SELECT @sql = 'select ''' + @dbname + ''' as db, o.name,m.definition ' SELECT @sql = @sql + ' from ' + @dbname + '.sys.sql_modules m ' SELECT @sql = @sql + ' inner join ' + @dbname + '..sysobjects o on m.object_id=o.id' SELECT @sql = @sql + ' where [definition] like ''%' + @text + '%''' EXECUTE (@sql) END --@dbname is not null … Continue reading Searching for Text Within a Stored Procedure
See All of Your Code!
No matter how big your screen resolution is, it seems we write a line of code wider than the width of the code editor window in Visual Studio. One solution is to break up your line using carriage returns (now works without the “_” character in VB.NET too). This issue with this is that every … Continue reading See All of Your Code!
Saving & Loading Application Settings in C#
If your application uses application settings that are the scope of “User”, in C# you will need to add code that will save and load these settings during shutdown and startup (this is automatic when using VB.NET). In your Main() method of the Program.cs file add the first two lines below to load the settings … Continue reading Saving & Loading Application Settings in C#
Prevent Thread Exceptions in ASP.NET
In ASP.NET, if you see Exception messages like this: Thread was being aborted. Coming from: System.Web.HttpResponse.Redirect This is due to the default behavior of the Redirect call and it always throws this exception that is usually absorbed by ASP.NET. You might see this if you are using Exception logging in your application. So make sure … Continue reading Prevent Thread Exceptions in ASP.NET

You must be logged in to post a comment.