Handle multiple files with one instance of the program [duplicate] - c#

This question already has answers here:
Open all files when user right clicks and selects "Open With"
(2 answers)
Closed 5 years ago.
Basically the problem is that I'am trying to open files with the program I made by right clicking on the file and open with... It works fine for a single file but when I try to open multiple files at the same time it starts an instance of the program for each individual file.
Finally, What I'am trying to get to is a way of changing this behavior in order to make one instance of the program handle all files.
Thanks,

You could check to see if there is already an instance of the program running before you initialize the window then send the file path to the open program or something along those lines

You won't like the answer as it gets complex but it is already answered here...
Open all files when user right clicks and selects "Open With"

Related

How to get a WPF app to open another app if it exists [duplicate]

This question already has answers here:
Check if an executable exists in the Windows path
(8 answers)
Closed 3 years ago.
I am working on a WPF app, and I would like to include a button that directs it to another app. I would like it to have the following functionality:
If the app is installed on the user's computer, it opens the app for them.
If the app is not yet installed, it sends them to a link where they can download the app.
I know I will need to use Process.Start to open the app, but I am stuck on how to check if the app exists. If anyone could point me in the right direction it would be appreciated!
Two things you can use:
File.Exists(string) - Checks if the file exists.
try-catch - Simply try to open it, and handle any exceptions.
I would probably opt for the first solution...

How do I do I select multiple files? [duplicate]

This question already has answers here:
Opening multiple files (OpenFileDialog, C#)
(2 answers)
Closed 3 years ago.
I need to select multiple files from the browse button. Right now, my code only selects one file. I need to select multiple files (by pressing control on Windows or command on Mac) and process them individually.I want a file per each line in my textbox.
OpenFileDialog has a Multiselect property.
Add this into your code(before showing the dialog).
fd.Multiselect = true;

How I can play audio in C# console application? [duplicate]

This question already has answers here:
How to play a sound in C#, .NET
(7 answers)
Closed 3 years ago.
I would like to know if it possible just play some kind of audio file in C# Console Application.
I don't find any answer on this question.
Many Thanks
In command prompt you can play an audio file by typing it's name from location folder:
c:\my_Music>track1.mp3
This opens the file with the format's associated progam so there will be a pop-up of an external program. Set program by using right-click on a file and choose "Open With".
I've not tested this in a console app. But you should be able to type a String into the console app and then trigger an ENTER press event.
Option 2:
Use SoundPlayer class.
A good tutorial for beginners. Also can check this: Playing sounds on Console.

How to enter text into CMD windows? [duplicate]

This question already has answers here:
Run interactive command line exe using c#
(3 answers)
Closed 6 years ago.
I can't seem to find a possible solution for entering 1 line of "command" into a CMD window. I searched the MSDN and asked google and they only found me solutions to enter text into a textfile, but that's not the same I guess.
Thank you in advance!
You're going to have to start the Minecraft service process from your .NET application. Whatever you've got now in the batch file you're using, you can duplicate that in the Process start code in C#, or you can just have your C# code run the batch file.
If you want a config file providing startup parameters, you could put that stuff in app.config and have your application give them to the Minecraft server process on startup.
Once you've got the process started, your application can keep the Process object and send repeated commands to its standard input stream, as outlined in this answer.
System.Diagnostics.Process.Start("CMD.exe", [your command]);

Detect whenever a specific file type gets opened [duplicate]

This question already has answers here:
Intercept windows open file
(4 answers)
Closed 7 years ago.
Is there an easy-to-implement method to detect whenever a user opens a file?(double click, right click, etc.)
I've read this but I think it only polls the file's lastaccess time. The main goal that I'm trying to achieve is whenever a user opens a file, the code picks up file name, location, size and all that good stuff.
I don't think I can ask this in any other way. I'm at a loss as to where to start.
Actually, the FileSystemWatcher from your linked question is the correct way to go. It does NOT poll anything, it listens to the OS events for file access. If there is no OS event, you cannot react to it.

Categories