I have a console application that converts .txt files into .xml files. I made a WinForms application to make a menu and select a Console Application and run it. The user can choose the paths of the input files through a browse button, and it insert the paths as string into some textboxes. Now I want the Console App to read what they say so it can locate the input files.
Is there any way to do this?
It is pretty easy to launch a console app from a WinForms app by simply using a process. Example:
Process.Start("myConsoleApp.exe", "some arguments");
However, the only time this makes sense is when the console app is not your own code. Or if it is your own code, but it is a generic app that is called from different UIs or methods.
If none of the above is the case (which seems to be your case), it makes more sense to merge the UI and functionality in one app. You wanted the menu to be a generic app that calls different apps, so simply remove the UI related to the console app, make it a separate WinForms app, and add the code from the console app to it. Now your menu app will simply call a WinForms app that has the UI and functionality all in one. You will use the same method above, but likely you don't need to pass any arguments:
Process.Start("myWinformsApp.exe");
From your winform application you can launch another process (probably by passing exe path of console app you talking about and relevant i/p parameter of type string which is basically path of your text file provided by user)
This link might help you do that.
Related
I need to write a very small application which writes some system data to a file and then exits. I could do this in a console application but I have no need or desire for a console window to appear during this process.
I would normally use a Windows Forms application with no forms, execute the code in the Main method and then allow the application to exit, however, this time I couldn't help but wonder if this is the best way to do it and whether you could do it with a WPF application instead, what the differences are and whether or not once you've remove any forms/windows and unnecessary reference, it matters or not.
WPF and WinForms are two different libraries that show UIs.
If you never show a UI, you aren't using either of them.
You should start with a WinForms project (WPF projects set extra project metadata that you don't want), then delete the reference to System.Windows.Forms.dll.
Alternatively, start with a console project, then change the Output type to Windows Application.
Windows Forms with no window or console app with the type changes to windows application will give you the same result which is a simple app with Main() method and now windows.
WCF will only make sense if you actually want to display something as you're not going to use any of its features in your case.
I was wondering if it is possible to open a second project (in the same solution as the first one) by code in the first project.
For example i have one form application project and another console application project.
The form application starts and when the user clicks a button i want the console application to run and the form application to stop.
Or could someone tell me how to delete my application .exe file?
The projects don't need to be in the same solution to do that. Just use Process.Start to start the executable for another application, and then close the main form to end the current application.
If you don't want to run the code as an entirely different process then it may also make sense to have a 3rd project that is a "class library" that the other two projects could add a reference to. This would allow you to define common code used in either application, using classes that are generalized to be helpful in either project.
I'm not sure what you're trying to do; but Process class has Start and Kill methods that will let you launch / exit processes.
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx
I am working on a Windows 8 app which is a collection of many Apps.Now what I want is I want to RUN the small Apps inside of the Main App.My main App will be available on Store but the Sub-Apps will not be available.They will be available only inside My main APP.
Now my question is-
How can I Run the Sub-App on the click of the button which is a part of my MAIN APP.
I don't believe that you can launch a second application from the first directly. However, what you can do is launch a file, which will cause the default app for the file to launch.
bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
Having said that, you have stated that the "sub apps" will not be available in the store. Is what you actually want here simply to encapsulate different aspects of your functionality within separate screens? You can expose this to the user through in-app purchases if that's your intent.
Another possibility would be to look at a background task if you are trying to relegate some heavy processing or something to a separate app.
I've got a console application and I want to run it from another application. But when I invoke it from code--to call program I use ActiveXObject--it shows the console. How do I get it to not show the console? I mean, the program works but console is shown.
If you make the application a Windows Application instead of a Console Application it will not show or open (or use) a Console. Your code can stay the same - and the application will still function (without ever creating a Form or Window).
That being said, if you control the "other" application, you may want to consider making a class library instead of a separate Application. This would allow you to just include and run code within the library without starting a separate process.
You can create it as a Windows Forms application with a hidden window. That's just one possibility like Reed Copsey pointed out, i used it once because i needed to process some specific Window Messages.
I have a C# Console app than runs a pre-build step (to get NuGet Packages).
When I am debugging this, I want to pass in a parameter and show the console. When I am not debugging it I don't want to see it. I don't even want it to flash up there for a second.
I have found ways to hide it, after it has shown. But I can't find a way to never make it show unless I am willing to change it from a console app to a Windows app. (Which I would do if I could then find a way to show the Console when needed.)
Build as a Windows application and show the console when you need it. To show the console when needed use P/Invoke to call AllocConsole (pinvoke.net has the declaration you need).
(Console sub-system processes always get a console, their parent process's if there was one, otherwise a new one. This is the way Windows works at a deep level.)
Use FreeConsole WINAPI function:
http://pinvoke.net/default.aspx/kernel32/FreeConsole.html
Another solution is to simply switch to a WinForms application as project type. No console will be allocated then (and you do not need to show a form).