Jun 2, 2017 08:43 AM
(This post was last modified: Jun 2, 2017 08:44 AM by Formula 1.)
I want to let it run an exe file that is already exist in the computer, just for 10 seconds then close that exe file.
Help anyone? =/
(Jun 2, 2017 08:43 AM)Formula 1 Wrote: I want to let it run an exe file that is already exist in the computer, just for 10 seconds then close that exe file.
Help anyone? =/
A quick solution would be to use a timer.
DO NOT DEAL WITH THIS MEMBER
The easiest solution would be to just use a timer as suggested above by @eCoLoGy... Within your timer tick event you can just increment a variable, make sure it is set to 1000ms (1 second) and once the variable reaches 10 that means 10 seconds is up so then you can just Application.Exit.
(Jun 2, 2017 09:10 AM)Owl Wrote: My suggestion:
Code Dim p As New Process With {
.StartInfo = New ProcessStartInfo With {
.FileName = "path"
},
.EnableRaisingEvents = True
}
AddHandler p.Exited, Sub(o, e)
Console.WriteLine("quit")
End Sub
p.Start()
Await Task.Delay(10000)
p.Kill()
I'd say this is the best way provided thus far, but there is no need to use Task.Delay. You can use WaitForExit(10000) instead which returns a boolean. Check that value to determine whether or not Kill needs to be called on the process.
Need a custom software? Check out my freelance service here! 6+ years and counting, never a complaint :)
STOP STEALING CODE.
FREE NATHAN
People who report posts are lamers.
From my understanding you want to run an exe file from your application, correct?
I don't see any reason why this wouldn't work.
Code Dim KillMe As New System.Diagnostics.Process()
KillMe.StartInfo.FileName = "Some/Folder/Some/File.exe"
KillMe.Start()
System.Threading.Thread.Sleep(10000)
KillMe.Kill()
(Jun 4, 2017 02:03 AM)Lord Wrote: From my understanding you want to run an exe file from your application, correct?
I don't see any reason why this wouldn't work.
Code Dim KillMe As New System.Diagnostics.Process()
KillMe.StartInfo.FileName = "Some/Folder/Some/File.exe"
KillMe.Start()
System.Threading.Thread.Sleep(10000)
KillMe.Kill()
Worked perfectly, Thank you!
1 more thing, how can i run it minimized ?
The exe program that i ran, i want it to be minimized...
DO NOT DEAL WITH THIS MEMBER
(Jun 4, 2017 07:03 AM)Formula 1 Wrote: Worked perfectly, Thank you!
1 more thing, how can i run it minimized ?
The exe program that i ran, i want it to be minimized...
You went with the worst suggestion out of all of them? Why?
(Jun 4, 2017 07:47 AM)log dot zip Wrote: You went with the worst suggestion out of all of them? Why?
I just want to run it for few seconds, its simple and works fine.. so why not?
DO NOT DEAL WITH THIS MEMBER
(Jun 4, 2017 07:49 AM)Formula 1 Wrote: I just want to run it for few seconds, its simple and works fine.. so why not?
Orkas suggestion was the best. You had to literally just copy paste it.
(Jun 2, 2017 09:10 AM)Owl Wrote: My suggestion:
Code Dim p As New Process With {
.StartInfo = New ProcessStartInfo With {
.FileName = "path"
},
.EnableRaisingEvents = True
}
AddHandler p.Exited, Sub(o, e)
Console.WriteLine("quit")
End Sub
p.Start()
Await Task.Delay(10000)
p.Kill()
Got some errors bro
DO NOT DEAL WITH THIS MEMBER
(Jun 4, 2017 10:11 AM)Formula 1 Wrote: Got some errors bro
How about, this might sound stupid LOL but hear me out, you POST THE ERRORS?
Jun 5, 2017 02:03 AM
(This post was last modified: Jun 5, 2017 02:05 AM by Washi.)
(Jun 4, 2017 07:47 AM)log dot zip Wrote: You went with the worst suggestion out of all of them? Why?
Care to elaborate why it is the worst? In a single-threaded application, this is perfectly fine. In a multi-threaded application (like GUI applications), if you'd run this on a separate thread, this would cause no problems either. Thread.Sleep is not evil or something, if that's the thing you are looking at.
(Jun 3, 2017 12:53 AM)idb. Wrote: ...
You can use WaitForExit(10000) instead which returns a boolean. Check that value to determine whether or not Kill needs to be called on the process.
Good point, but that also implies that you can interrupt the 10 seconds waiting time if the application closes earlier than 10 seconds. Not sure if that is the case in OP's question.
(Jun 4, 2017 10:12 AM)Ninja Wrote: How about, this might sound stupid LOL but hear me out, you POST THE ERRORS?
Lol'd
|