1
I’m trying like this:
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.ShowDialog();
string filePath = openFileDialog.FileName;
Process processo = Process.Start(filePath);
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None);
processo.WaitForExit();
MessageBox.Show("Wow!");
fileStream.Close();
It seems to me that fileStream blocks the file before it is opened, so of the error, one of the errors it gives is this:
---------------------------
Desenhar matriz.exe - This application could not be started.
---------------------------
This application could not be started.
Do you want to view information about this issue?
---------------------------
Sim Não
---------------------------
Isn’t there a process thread already running? I don’t know much about C#, but this
Process.Start(filePath);
does not make much sense. It is trying to run the file as if it were an executable. This must be why the application ends.– Guilherme Nascimento
It opens normal, the problem is when I put this fileStream command right away, I already tried to put a messagebox to intercept, so it works, the problem is, in how many seconds should I block? Got it?
– Ícaro Dantas
But you understood what I said, that
Process.Start(filePath);
here is not making sense. What is the reason for this, you have full knowledge of what theProcess.Start
does and how it works. I believe that you are using the code randomly, this line is meaningless, it’s like you want the file to become an executable.– Guilherme Nascimento
I want exclusive access, the intention is to run it and block in a way "gambiarra" while the process is running.
– Ícaro Dantas
Icaro I understood the intention and goal, what doesn’t make sense is your code, the way you’re using Process.Start isn’t making sense, it’s that seems to be the whole problem, you know? It must be a problem that triggers another. ;)
– Guilherme Nascimento
But I want to run, I want to make the program really open.
– Ícaro Dantas
So filePath is not a file but another executable? Or is a executable that calls another?
– Guilherme Nascimento
No, I run a program x and then I open it with the stream kind of to block understood?
– Ícaro Dantas
I don’t understand, this confused, you want the matrix.exe program to call itself and be "blocked" using Filestream?
– Guilherme Nascimento
No, a C# program calls an X program and makes it impossible to copy, etc.
– Ícaro Dantas
Oh understood, edit the question and put these details. Just a hint, try to change the order to
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None);
Process processo = Process.Start(filePath);
processo.WaitForExit();
and see if it works– Guilherme Nascimento
Same thing, it’s more complicated than it looks.
– Ícaro Dantas