?
Solved

How to run same application as a console(scheduled application) and in windows form(manual)

Posted on 2006-07-17
8
Medium Priority
?
224 Views
Last Modified: 2010-04-16
I want to develop an application. Basic thing to do for it is to look for files in a folder. When it finds files, do some action and delete files. However, this is an scheduled once a day routine. Sometimes, I should be able to forcefully run this application and enter the filename and do action only to that filename without bothering other files. How can I utilize these both events in one application.
Please help.
0
Comment
Question by:sovroc81
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 

Author Comment

by:sovroc81
ID: 17124855
Same question can be asked this way.

In the start of the console window application, can I make user to input filename by waiting for 15 seconds or so. If I don't get the input within that time, can I proceed with Process1 else proceed with Process2.

The input can be accepted in the form of any keystroke (if not the whole fileName).

I don't how to make them wait for 15 second for the response.
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 17125315
Why not just make the filename an input argument, and have another input argument to tell in to run in "auto" mode (so you don't accidentally run in auto mode if you forget to add parameters)?

e.g.

MyApp.exe -f *.txt   // process all text files
MyApp.exe -f textfile.txt // process single file
MyApp.exe -a // Auto processing (maybe with defaults specified in config.xml)
MyApp.exe -? // Show syntax and options.
0
 

Author Comment

by:sovroc81
ID: 17125352
Can you give an example of what you are trying to say?
Thank you!!!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sovroc81
ID: 17125375
According to your example, you are asking me to input value in commandline for each time I call manually. Is their a easier way to invoke exe file with parameters. Can I do it in a small window application instead, obtaining the parameter from a textbox.
0
 
LVL 25

Accepted Solution

by:
dstanley9 earned 2000 total points
ID: 17125479
the args parameter of the Main method is where the command-line arguments are stored:

 static void Main(string[] args)
 {

     if (args.Length < 1)
         ShowUsage();
     switch (args[0])
     {
         case "-?":
             ShowUsage();
             break;
         case "-f":
             // process one file or several files using mask from args[1]
             break;
         case "-a":
             // Automatic mode - use defaults from somewhere (e.g. config.xml)
             break;
         default:
             ShowUsage();
             break;
     }
     return;
 }
 private void ShowUsage()
 {
     Console.WriteLine("");
     Console.WriteLine("usage: MyApp.exe  {option}");
     Console.WriteLine("  options:");
     Console.WriteLine("-? Show this help information");
     Console.WriteLine("-a Run in automatic mode");
     Console.WriteLine("-f {filemask} process one file or all files matching the file mask");
     Console.WriteLine("");
 }

If you have a certain filename that you process regularly, you could add an option to process that without having to supply the name of the file.


For your other question, sure you can put it in a Windwos app, but if you want to run it as a scheduled task, a Console app would work much better.
0
 

Author Comment

by:sovroc81
ID: 17125606
Thanks for your promptness.
Can you show me how to put this into a separate window application and call from there?
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 17125637
Build the logic pieces as a class library (DLL), then reference the class library from your console app, and also create a Windows app that references and uses the classes.  There's not really a "cookie-cutter" way to do it.

To be honest, the console app with parameters will be much easier to build; adding on a GUI after the fact will take some re-writing.
0
 

Author Comment

by:sovroc81
ID: 17125964
You are right. It is definitely a painstaking process, but at this time, I got the answer and I got it right.

Thanks for your help for showing the insight.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question