Monday, February 11, 2008

Return an exit code from a C# Windows Application

To exit an Windows Forms Application, we have the option to use Application.Exit() or the System.Environment.Exit().

The difference is discussed here (http://geekswithblogs.net/mtreadwell/archive/2004/06/06/6123.aspx) and the suggestion was made to use System.Environment.Exit() for console applications since it can accept an exit code which will be returned to the Operating System.

But for Windows applications, what should we do ?

I have tried to modify the Main function definition so it will have a return value, a lesson learned from C/C++ old days, then add a property to my main form to indicate if my application would report a success or failure report

And so, my Main function will look like this :

 

        [STAThread]
       
static int Main(string[] arguments)
        {

            Application.EnableVisualStyles()
;
           
Application.SetCompatibleTextRenderingDefault(false);

           
MainForm mainForm = new MainForm();
            Application.Run(mainForm)
;

           
//return exit code
            // 0  : no problem
            // -1 : error occured

           
int exitCode = mainForm.Succeeded == true ? 0 : -1;
            return
exitCode;
           

       
}

 

This approach can be extended to report different exit codes for different scenarios (think about MSBuild or NAnt exit codes).

Saturday, February 09, 2008

Guidelines for Test-Driven Development

 

Jeffrey Palermo has an interesting article on MSDN about TDD in .net development, discussing the process of Red-Green-Refactor, benefits of TDD and what characterizes a good unit test

Microsoft Sync Framework

According to Microsoft definition; the Sync Framework is "a comprehensive synchronization platform enabling collaboration and offline for applications, services and devices with support for any data type, any data store, any transfer protocol, and network topology."

What does it mean for us developers?

Hmmm, I am trying to think about an example here. Take Microsoft Outlook and Microsoft Groove as an example; both are collaboration platforms, can work offline and online, and support many protocols.

Look at the technical options that we have now if we need to build something like this:

  • Database Replication
  • Offline Application Block
  • WCF with Queued Messages

I don't know of any other option, but each of the above options has different approach and has issues and limitations as well.

The Sync framework is coming to put a uniform way of building applications like Outlook without pain, the framework is now addressing Data, files and feeds synchronization in addition to having the ability to role your own providers; think about synchronizing an Oracle database with an Outlook folder or a SharePoint list.

The concept is discussed in Introduction to the Microsoft Sync Framework Runtime , while the motivations, goals and approach is briefly discussed by Moe Khosravy the Lead Program Manager on his article Next Generation Synchronization Framework or watch him talk about it on Channel8 http://channel8.msdn.com/Posts/Sync-your-Facebook-with-your-phone-Whats-the-Sync-Framework/

There is also a number of Screen casts http://blogs.msdn.com/sync/archive/2008/01/14/microsoft-sync-framework-sync-services-for-ado-net-video-webcasts.aspx

So, what are you waiting for, go ahead and download the SDK (http://www.microsoft.com/downloads/details.aspx?FamilyId=C88BA2D1-CEF3-4149-B301-9B056E7FB1E6&displaylang=en) and start playing.

Interested on the subject, or have played with it … let me know by commenting on this post

Friday, February 08, 2008

[Architecting Desktop Applications with 2.0] MSDN Webcast series

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 01 of 15): Smart Clients and N-tier Design (Level 300)

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 02 of 15): Design Patterns for GUI Applications (Level 300)

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 03 of 15): Creating Dynamic and Configurable Applications (Level 300)

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 04 of 15): Architecting a Secure Desktop Application (Level 300)

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 05 of 15): Designing the Business Tier (Level 300)

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 06 of 15): Designing the Data Access Tier (Level 300)

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 07 of 15): Best Practices for Developing N-Tier Applications (Level 300)

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 08 of 15): Turning Tiers into Components (Level 300)

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 09 of 15): Build, Build, Build, Test, Test, Test (Level 300)

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 10 of 15): Multithreading for Performance and Responsiveness (Level 300) (Level 300)

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 11 of 15): Designing Distributed Applications Around Remote Access (Level 300) (Level 300)

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 12 of 15): Designing Distributed Applications Around Web Services (Level 300) (Level 300)

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 13 of 15): Securing a Distributed Application (Level 300) (Level 300)

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 14 of 15): ClickOnce Deployment (Level 300) (Level 300)

MSDN Webcast: Architecting Desktop Applications with 2.0 (Part 15 of 15): Learning from Agile Development (Level 300) (Level 300)