Calvin Hsia's WebLog

thoughts from a professional developer

Browse by Tags

Tagged Content List
  • Blog Post: Scan the Windows Event Log for your application crashes and hangs

    When you write software that runs on someone’s machine, it might crash or hang. If this occurs, there are ways to see if this occurred from your program. For example, I wrote a simple application in C++ called CppTest that crashes by dereferencing a null: char *ptr = 0; *ptr = 0; Lo and behold: my custom...
  • Blog Post: Cartoon animation works great on Surface Pro

    I showed my 9 year old son a cool drawing program called Physamajig , in which users can draw objects, which behave like real physical objects, including reacting to gravity, friction, and bounce. He was having fun with it on my Surface RT and it reminded me of another program. Years ago (around 1981...
  • Blog Post: Its easy to Create your own FrameWorkElement in WPF

    Sometimes you want to have very fine control of how your application looks and behaves. Other times, you just want to draw something on your UI. It’s pretty easy to create your own control class and put instances of it on your form. The sample below create a new class MyFrameworkElement which allows...
  • Blog Post: Examine your program's available memory: is it leaking?

      Sometimes your program wakes up and finds itself running in an environment that might not be as suitable as you’d like.   For example, it might be distributed to a user running on a machine with not enough memory, and could be failing. Perhaps the failures occur because the user is running...
  • Blog Post: Process Windows Messages in your WPF application

      I have some code that attaches and injects code into a target application (like Visual Studio or IE) to examine its memory use. In order to do that, my code freezes the target.   I wanted my application to respond to WM_QUERYENDSESSION so that when the user is shutting down, it unfreezes...
  • Blog Post: Advanced debugging: change your program execution without Edit and Continue

    Last time ( Improve your managed debugging skills: examining registers and memory ) we examined some debugging techniques to understand the behavior of managed code. It might take a long time or many manual steps to reproduce a particular software behavior in an application. Changing the instructions...
  • Blog Post: Improve your managed debugging skills: examining registers and memory

      I was helping a colleague and we were deep in the middle of a debug session, single stepping some code and we wanted to see a value in the debugger. The debugger showed either nothing, because the intermediate value has been optimized out, or a message like “cannot display value, possibly because...
  • Blog Post: Using and styling a treeview in WPF

      As you know, a treeview control is very useful for viewing hierarchical information. Each node in a tree can have its own parent/child relationships.   Some of these trees can be extremely large, and can thus be prohibitively expensive to calculate completely. Windows Explorer comes to mind...
  • Blog Post: Automatic tests protect your code

      Last month   in   Dynamically create huge tooltips in WPF TreeView and ListView I showed some code that creates large tooltips to present lots of data.   Today, we’ll talk about creating automatic tests for this feature.   Testing User Interface features has been difficult...
  • Blog Post: Dynamically create huge tooltips in WPF TreeView and ListView

      Tooltips are useful. When the mouse hovers over a button a tip can indicate what happens when it’s clicked. The mouse move does not actually invoke the button, but can give information in a passive way.   Sometimes I want to make huge tooltips. This essentially gives more screen real estate...
  • Blog Post: Returning data from a recursive method

    Sometimes you need to write a method that requires recursion to be elegant. Often that method needs to accumulate data between recursion levels There are many ways to do so, and some are more elegant than others. I like the Optional Parameter method: it requires no additional class or static (shared...
  • Blog Post: Embed a ListView inside another ListView for one to many relationships

    In the old days (about 16 years ago), FoxPro’s object, containership and inheritance models made it easy to put objects inside other objects. So, for example, a FoxPro grid of Customers could have a column containing a grid of each customer’s orders, and each order, in turn, could have a grid of the...
  • Blog Post: Use colors in WPF to show virtual memory fragmentation

    In this post What is your computer doing with all that memory? Write your own memory browser is sample code that shows how to create a WPF grid view of a memory map of a process. You can click on a column header to sort, and you can see the various loaded images and even a binary display of the actual...
  • Blog Post: See and hear the effects of Garbage Collection

    Sometimes you forget that GC’s occur: it’s hard to see it’s effect, but what does Garbage Collection do to your code? A long time ago (3 decades!) I used Fortran and Assembly code for a PDP-11 16 bit computer to design real time signal processing systems. Two of these were used...
  • Blog Post: 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...
  • Blog Post: Adding a new ADO.NET Entity Data Model "Error HRESULT E_FAIL has been returned from a call to a COM component"

    I tried adding a new ADO.NET Entity Data Model item to a VS 2010 solution, but I got this error message: Error HRESULT E_FAIL has been returned from a call to a COM component. It worked just a few days ago…hmmm…. I had another project open in another VS instance, and I had...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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. That’s...
  • Blog Post: 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...
  • Blog Post: 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 in code: Dim style As New Windows...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: Use Named Pipes and Shared Memory for inter process communication with a child process or two

    I wanted to inject some very low impact code that would run in any “parent” process, like Notepad or Excel or Visual Studio. I wanted to have some User Interface for the data that my injected code gathered about the parent process, and that would work best in a different “child” process, preferably using...
Page 1 of 5 (102 items) 12345