Jon Box's Weblog

 


.NET Articles by the Atomic group

MSDN RDs









Subscribe to "Jon Box's Weblog" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 

 

  Tuesday, July 08, 2003


Debug.Writeline("What just happened?")

I miss having debug output from System.Diagnostics.Debug class.  I use Debug.Writeline statements frequently.  But these debugging statements do nothing when working on a Pocket PC (PPC) and the .NET Compact Framework.  If you haven't experienced this yet, it is one of the areas in the .NETCF where an application compiles but appears to do nothing at runtime.

With the desktop framework, DEBUG messages show up in the Output window of VS.NET, but not yet for .NETCF applications.  This is due to missing communication functionality between VS.NET and the device framework in v1.

The Debug statements actually do have some functionality.  If using the managed Debug class on a CE H/PC (handheld), a console window would appear with the DEBUG messages.  But on a PPC, nothing happens due to no console existing in the PPC O/S.

MsgBox(“Debugging the Hard Way”)

There is one easy way to get output from debugging and that is to use MessageBox.Show or MsgBox.  While easy to do, this is inconvenient for several reasons.  First, clicking all of the messages is a pain.  Second, when the code needs to be deployed, the developer will have to remove the debug statements.  Be sure to check out the DEBUG constant so that you can use "#if DEBUG" statements around the code that should be removed for production.  Due to these reasons, I would still rather use the Debug class if it produced output.

Alternative Solutions for the Compact Framework

There are several alternatives for seeing diagnostic output from a debugged managed application.  Let's consider a few:

  • Use the NKDbgPrintW API call – I’m haven’t personally tried this but examples do exist
  • Write a class that persists to a file on the device - not preferable if you have to remove the code for production, check out that #DEBUG feature
  • Write a listener that persists to a file - more preferable than the previous option because the code will be omitted in Release mode
  • Use a 3rd party component

Let’s look a free solution.

The Free Solution

I found mention of a free solution, PocketConsole, on the Compact Framework newsgroup and had to check out. This software is a Pocket PC console device driver, not a command line hosting environment (although they have that as well and runs on top of the PocketConsole). PocketConsole is very simple to use – download to your desktop, install on the device, code using the Debug class, and start debugging.  That’s it.  And it’s even works on an emulator.

The only compromise from what I want is that the Debug output does not show up in VS.NET.  However, when debugging a program, the output will show up in a console window (i.e. text based) automatically, just like on a handheld.  Seeing the output presents a slight challenge.  First, the console window appears behind the application.  Second, terminating the debugged application on the device kills the debug output window as well. 

Due to these slight complications, there are some workarounds to consider.  Run with the Smart Minimize (i.e. Form.Minimize=true, which is the default) so that clicking the “X” button will minimize the application and then show the console which will have debug output. Then use the “Running Windows” screen to activate the application (or add the appropriate ICON’s so that the application is selectable).

Vacation in Baseball-land

For those who don't know me, my family is into baseball, possibly to an addictive level.  I have two sons who play a bunch, and my wife and I are involved in my second son's baseball team (an 11 year old team based in Memphis, I'm an assistant coach, she's team mom and scorekeeper).  I'm on vacation this week due to this team being in a World Series in Southaven, MS.  Even as I write this, we have just returned from playing our second game of the day.


12:23:57 AM    comment []


Click here to visit the Radio UserLand website. © Copyright 2004 Jon Box.
Last update: 8/31/2004; 11:54:32 PM.

July 2003
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Jun   Aug