InterviewSolution
| 1. |
Solve : Not sure why my code is not working? |
|
Answer» So im trying to create a program pretty much that will open other programs upon exit or with a time delay. I get no build errors but everytime i RUN my program i get the ERROR Cannot start process because a file name has not been provided. but launches the first program anyways just not the other one upon exit. anyone see any issues with the code i provided. Thanks alot appreciate any help Process.Start() isn't going to give the firstProc instance any information about the file you specified as a parameter, as it creates a new Process and starts it and returns that Process as the return value. thanks alot for the help im now using Code: [Select]ProcessStartInfo FirstProcInfo = new ProcessStartInfo(@"C:\Program Files (x86)\Steam\steamapps\common\BattleBlock Theater\BattleBlockTheater.exe"); var FirstProc = Process.Start(FirstProcInfo); firstProc.WaitForExit(); ProcessStartInfo SecondProcInfo = new ProcessStartInfo(@"C:\Program Files (x86)\Steam\steamapps\common\BattleBlock Theater\BattleBlockTheater.exe"); var SecondProc = Process.Start(SecondProcInfo); } catch (Exception ex) { Console.WriteLine("Something went wrong :) " + ex.Message); return; } } } } Not sure if it matters or not but im trying to open the same exe after it exits from the first one so opens up exe if you exit that exe it opens the same one up again. Not sure if that matters but im getting the method or operation is not implemented the first exe opens up correctly. the second one doesnt open up apon closing it thoThat code wouldn't even compile. You defined the v ariable as FirstProc but then used it as firstProc. anyway, Steam changes everything. When you launch a steam-managed game by itself it will launch steam telling it to launch itself and exit, so WaitForExit() will return immediately. I don't get "method or Operation is Not Implemented".Quote from: BC_Programmer on January 07, 2017, 03:40:11 PM That code wouldn't even compile. You defined the v ariable as FirstProc but then used it as firstProc. changed up my code a bit now compiles without any errors Code: [Select]using System; using System.Diagnostics; using System.Diagnostics.Contracts; using System.Threading.Tasks; namespace ProcessExitSample { class testsandboxprogram { static void Main(string[] args) { try { //why in the literal *censored* ProcessStartInfo FirstProcInfo = new ProcessStartInfo(@"C:\Program Files (x86)\Steam\steamapps\common\BattleBlock Theater\BattleBlockTheater.exe"); var FirstProc = Process.Start(FirstProcInfo); Console.WriteLine("First process Started: "); System.Threading.Thread.Sleep(4000); Task.Delay(2000); // should run the second program here ProcessStartInfo SecondProcInfo = new ProcessStartInfo(@"C:\Program Files (x86)\Steam\steamapps\common\BattleBlock Theater\BattleBlockTheater.exe"); var SecondProc = Process.Start(SecondProcInfo); } catch (Exception ex) { Console.WriteLine("Something went wrong :) " + ex.Message); return; } } } } the only thing now is session 1 terminates once session 2 launches decided ill just work with launching TWO at the same time. |
|