December 9, 2002

A Custom Proxy that Handles Thread Creation and Object Pooling

enerally, when a good programmer has to design a type (or a hierarchy of types), he does an analysis of the problem and then starts to write properties and methods that describe the type behavior. If a method requires long processing time, it is the perfect candidate for being called

GetLocalHostIpAddresses – Retrieving the array of IP addresses for the local host

‘ Return the array of IP addresses for the local host’ Note: Requires Imports System.Net’ Example:’ Dim ipa As IPAddress’ For Each ipa In GetLocalHostIpAddresses()’ Debug.WriteLine(ipa.ToString())’ NextFunction GetLocalHostIpAddresses() As IPAddress() Dim iphe As IPHostEntry = Dns.GetHostByName(Dns.GetHostName()) Return iphe.AddressList()End Function

SaveBinaryData – Serializing an object to file in binary format

‘ Serialize an object to file in binary format’ It can handle types that the SOAP serialization can’t’ Requires:’ Imports System.IO’ Imports System.Runtime.Serialization.Formatters.BinaryPrivate Sub SaveBinaryData(ByVal path As String, ByVal o As Object) ‘ Open a file stream for output. Dim fs As FileStream = New FileStream(path, FileMode.Create) ‘ Create a

GetOleDbType – Retrieving the OleDbType for the specified system type

‘ Return the OleDbType that represents the specified system type’ This is particularly useful when you have a DataTable and want to create a ‘ OleDbParameter for onw of its columns, but don’t know its type. ‘ DataColumnName.DataType returns a Type, and you can convert it to OleDbType ‘ by

LoadBinaryData – Deserializing an object from a file in binary format

‘ Deserialize an object from a file in binary format’ It can handle types that the SOAP serialization can’t’ Requires:’ Imports System.IO’ Imports System.Runtime.Serialization.Formatters.BinaryPrivate Function LoadBinaryData(ByVal path As String) As Object ‘ Open a file stream for input Dim fs As FileStream = New FileStream(path, FileMode.Open) ‘ Create a binary

Printing formatted text and other data with the WebBrowser control

Printing con be quite difficult in VB.NET (or any other .NET language), especially if you not only have to print plain text, but also tables, images, bulleted lists, text with different fonts, styles, colors and any other type of formatted data. Here’s a tip that can make your life much