Console Application

"R. Rogers" <[email protected]> Tue, 11 Dec 2007 13:29:37 -0500
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <005301c83c23$c97466f0$6800a8c0@Speedster>
Hi,

As far as I know, there's no forum for Console apps, so I'm placing my
questions here.

I'm just writing a simple console app:

namespace HierarchyTest
{
  class MyConsoleApp
  {
    private bool Initialize()
    {
      bool Result = false;

      return (Result);
    }

    private bool MainProcessing()
    {
      bool Result = false;

      return (Result);
    }

    private void Completion()
    {
    }

    static void Main(string[] args)
    {
    }
}

I have two questions:
1. Main is declared as static. As a result, I can't directly call
MyConsoleApp.Initialize() from within Main. I can take the approach of
either creating my methods as static, or writing something like this in
main:

      try
      {
        MyApp = new MyConsoleApp();
        if (MyApp.Initialize())
          if (MyApp.Processing())
          {
            MyApp.ProcessingMessage = String.Format(_ProcessingComplete,
MyApp.FoldersProcessed, MyApp.FilesProcessed);
            Console.WriteLine(MyApp.ProcessingMessage);
          }
        MyApp.Completion();
      }
      finally
      {
        if (MyApp != null)
          MyApp = null;
      }

Which approach do you take in your console apps, and why?

2. I'd like to use a 'using' instead of a try/finally block, but MyApp
doesn't implement IDisposable, hence the following code won't compile:

      using (MyApp = new MyConsoleApp())
      {
        if (MyApp.Initialize())
          if (MyApp.MainProcessing())
          {
            MyApp.ProcessingMessage = String.Format(_ProcessingComplete,
MyApp.FoldersProcessed, MyApp.FilesProcessed);
            Console.WriteLine(MyApp.ProcessingMessage);
          }
        MyApp.Completion();
      }

What would you do? Would you declare MyConoleApp this way?
class MyConsoleApp : System.Idisposable

Thanks for any/all feedback.

Richard Rogers
http://www.RichardRogers.ca/
(MSN) [email protected]