Windows Forms and Console Application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dm1608

    #1

    Windows Forms and Console Application

    Hi --

    I have a VB6 application that I plan on rewriting in C#.NET. The program
    today basically connects to a SQL Server and parses varies system stats from
    our mainframes and rolls the data up for up/downtime statistics, etc.

    Since the current program today requires me to click various buttons and
    tabs to load/review the information being parses and saved, I would like to
    implement this applications as both a Windows Forms and Console application.
    My thought was that I can run the Windows Form application like normal and
    manually click buttons and stuff to perform the desired function. However,
    I would also like the ability to run the .EXE via a scheduler, if needed, to
    automated this process as well.

    Can anybody provide me some points on how I can have both features in the
    same application?

    In addition, how can I check whether I'm running in console mode vs windows
    mode in order to execute the correct events automatically?

    Thanks for any help.



  • Chris Dunaway

    #2
    Re: Windows Forms and Console Application

    Develop it as a normal Windows Application with your forms, buttons,
    etc., but start it using a main method that will allow you pass command
    line arguments. Then, based on the arguments passed, you can either
    show the main form for manual operation or execute the code without
    showing the main form based on the parameters passed in.

    I wouldn't worry about using a true console app. A normal Windows app
    should work. You will have to design it so the UI is separated from
    the main functionality of the app so that you can execute the code both
    from the UI and from the command line.

    Comment

    • Nick Hounsome

      #3
      Re: Windows Forms and Console Application


      "dm1608" <dm1608@spam.ne t> wrote in message
      news:OpUsD6PdGH A.3888@TK2MSFTN GP02.phx.gbl...[color=blue]
      > Hi --
      >
      > I have a VB6 application that I plan on rewriting in C#.NET. The program
      > today basically connects to a SQL Server and parses varies system stats
      > from our mainframes and rolls the data up for up/downtime statistics, etc.
      >
      > Since the current program today requires me to click various buttons and
      > tabs to load/review the information being parses and saved, I would like
      > to implement this applications as both a Windows Forms and Console
      > application. My thought was that I can run the Windows Form application
      > like normal and manually click buttons and stuff to perform the desired
      > function. However, I would also like the ability to run the .EXE via a
      > scheduler, if needed, to automated this process as well.
      >
      > Can anybody provide me some points on how I can have both features in the
      > same application?
      >
      > In addition, how can I check whether I'm running in console mode vs
      > windows mode in order to execute the correct events automatically?
      >
      > Thanks for any help.[/color]

      I would put all the functionality into a non-GUI class and put that in a dll
      and then write separate GUI and command line exes to use it. The advantage
      of this is that you have the flexibility to add new GUIs or commandline
      switches without changing the core stuff.


      Comment

      • Bob Powell [MVP]

        #4
        Re: Windows Forms and Console Application

        I've just done almost exactly this. Here's how...

        Create a DLL that has the main engine which provides a class having methods
        and properties as needed.

        For long operations, provide an event that may be handled so that the engine
        can suggest a good time to yield to the OS, such as calling
        Application.DoE vents.

        For command-line usage, load a console app that takes parameters and calls
        the required methods on an instance of your engine class

        for UI based usage, create an instance of the engine class, handle the yield
        event if needed with a call to Application.DoE vents and create a Dialog
        style front-end to drive the methods of the engine class instance.

        --
        Bob Powell [MVP]
        Visual C#, System.Drawing

        Ramuseco Limited .NET consulting


        Find great Windows Forms articles in Windows Forms Tips and Tricks


        Answer those GDI+ questions with the GDI+ FAQ


        All new articles provide code in C# and VB.NET.
        Subscribe to the RSS feeds provided and never miss a new article.



        "dm1608" <dm1608@spam.ne t> wrote in message
        news:OpUsD6PdGH A.3888@TK2MSFTN GP02.phx.gbl...[color=blue]
        > Hi --
        >
        > I have a VB6 application that I plan on rewriting in C#.NET. The program
        > today basically connects to a SQL Server and parses varies system stats
        > from our mainframes and rolls the data up for up/downtime statistics, etc.
        >
        > Since the current program today requires me to click various buttons and
        > tabs to load/review the information being parses and saved, I would like
        > to implement this applications as both a Windows Forms and Console
        > application. My thought was that I can run the Windows Form application
        > like normal and manually click buttons and stuff to perform the desired
        > function. However, I would also like the ability to run the .EXE via a
        > scheduler, if needed, to automated this process as well.
        >
        > Can anybody provide me some points on how I can have both features in the
        > same application?
        >
        > In addition, how can I check whether I'm running in console mode vs
        > windows mode in order to execute the correct events automatically?
        >
        > Thanks for any help.
        >
        >
        >[/color]


        Comment

        • dm1608

          #5
          Re: Windows Forms and Console Application

          How --

          Can you explain more about the events?

          Most of what I will be doing will be SQL queries. Some take 10-15 secs...
          others take 1-2 mins depending on how busy the SQL Server is. Is there a
          way I can do events for this?

          Also, how did you handle the checking of args and whether you're launching
          or form or not?

          Any help would be appreciated.




          "Bob Powell [MVP]" <bob@_spamkille r_.bobpowell.ne t> wrote in message
          news:eGYoP1TdGH A.3348@TK2MSFTN GP03.phx.gbl...[color=blue]
          > I've just done almost exactly this. Here's how...
          >
          > Create a DLL that has the main engine which provides a class having
          > methods and properties as needed.
          >
          > For long operations, provide an event that may be handled so that the
          > engine can suggest a good time to yield to the OS, such as calling
          > Application.DoE vents.
          >
          > For command-line usage, load a console app that takes parameters and calls
          > the required methods on an instance of your engine class
          >
          > for UI based usage, create an instance of the engine class, handle the
          > yield event if needed with a call to Application.DoE vents and create a
          > Dialog style front-end to drive the methods of the engine class instance.
          >
          > --
          > Bob Powell [MVP]
          > Visual C#, System.Drawing
          >
          > Ramuseco Limited .NET consulting
          > http://www.ramuseco.com
          >
          > Find great Windows Forms articles in Windows Forms Tips and Tricks
          > http://www.bobpowell.net/tipstricks.htm
          >
          > Answer those GDI+ questions with the GDI+ FAQ
          > http://www.bobpowell.net/faqmain.htm
          >
          > All new articles provide code in C# and VB.NET.
          > Subscribe to the RSS feeds provided and never miss a new article.
          >
          >
          >
          > "dm1608" <dm1608@spam.ne t> wrote in message
          > news:OpUsD6PdGH A.3888@TK2MSFTN GP02.phx.gbl...[color=green]
          >> Hi --
          >>
          >> I have a VB6 application that I plan on rewriting in C#.NET. The program
          >> today basically connects to a SQL Server and parses varies system stats
          >> from our mainframes and rolls the data up for up/downtime statistics,
          >> etc.
          >>
          >> Since the current program today requires me to click various buttons and
          >> tabs to load/review the information being parses and saved, I would like
          >> to implement this applications as both a Windows Forms and Console
          >> application. My thought was that I can run the Windows Form application
          >> like normal and manually click buttons and stuff to perform the desired
          >> function. However, I would also like the ability to run the .EXE via a
          >> scheduler, if needed, to automated this process as well.
          >>
          >> Can anybody provide me some points on how I can have both features in the
          >> same application?
          >>
          >> In addition, how can I check whether I'm running in console mode vs
          >> windows mode in order to execute the correct events automatically?
          >>
          >> Thanks for any help.
          >>
          >>
          >>[/color]
          >
          >[/color]


          Comment

          Working...