Write your own Linq query viewer

Sometimes you just want to see data in a tabular format. It could be stored in a server somewhere in the cloud, in a SQL server, a FoxPro database, an EntityFramework object, or just a local object. You’d like to see all columns, without having to write code to select each column.   Linq allows…


Why does your code take so long? Profile it!

Why does your code take so long to run? How do you improve its performance? When examining code, it’s very difficult to know which piece takes the longest, and thus should be the target of you optimization efforts.   For example, you won’t see much benefit from optimizing a part of your code if that…


Collect system info for your application’s runtime environment

Often your code gets run on a machine far away and it’s useful to gather some information about that machine automatically, perhaps for error reporting or statistics gathering. This information could include the Operating System version, how much memory, logged in user, etc.   There are various means of gathering such information. Rather than using…


Out of memory? Easy ways to increase the memory available to your program

When you run your VB or C# application, you might get an OutOfMemoryException thrown, even if your  machine has lots of  memory.   Every 32 bit process has a 2^32 bit (4 Gig) address space. That means every pointer has a size of 32 bits (4 bytes) and thus is limited to 4 Billion.  …


Use Perfmon to analyze your managed memory

You can learn all sorts of information about your application using Perfmon. You can also inspect various aspects of managed memory.   How much time is spent in garbage collection? When managed code runs, memory management is done for you, but at the cost of freezing your application while GC is doing its thing.  …


Use inline XAML with clr-namespace to create a Styled Treeview

Writing WPF code is made easier in VB because of the built in XML features (XAML is really XML).  Here is a sample that creates a TreeView of some folders on disk.   Suppose we want to add a Trigger style that will fire when the mouse is over an item. We could do it…


Using multiple heaps efficiently

You can inspect the processes that run on your machine using Task Manager (Ctrl-Shift-Escape) or , Process Explorer from Sysinternals   Or you can write your own: here’s source code: What is your computer doing with all that memory? Write your own memory browser (if you’re using Dev10, just change “Class Window1” to “Class MainWindow”)…


Managed code using unmanaged memory: HeapCreate, Peek and Poke

In the old days of Basic (starting over 4 decades ago), there were functions called Peek and Poke that would allow you to read and write memory directly. These were incredibly powerful commands: you could, for example, read and write directly to the hardware, like the video display, the tape cassette recorder, or the speaker….


Sometimes you want 2 returned values: playing around with Tuples

When writing code in various languages, you’ll write functions from which you get a return value.   Sometimes you’ll want to get 2 return values. A common way to handle this is to use parameters to pass a variable by reference that will get one of the return values. Alternatively, you could use a Structure,…