C
C#13mo ago
MorganIGuess

How do I make my Process.Start automatically end after it's done playing?

I'm making my Process.Start play a video within the same file folder however I want it to automatically close on its own after it's done, and not by the user manually clicking exit I tried doing WaitForExit and Close but it displays: System.NullReferenceException: 'Object reference not set to an instance of an object.'
No description
11 Replies
MorganIGuess
MorganIGuessOP13mo ago
No description
wasabi
wasabi13mo ago
Process.Start is not guarenteed to return a handle to a new Process. As it is, what you're doing, is instructing the command shell (cmd.exe) to run a command. That command may simply not run a process. In your case, what you're doing is equiv to typing foo.mp4 on the Windows command line. Which might open it in an existing instance of a media player. Or start a new instance. Using the default platform file association. Which may not open a process. >Process.Start
Returns:
>A new Process that is associated with the process resource, or null if no process resource is started. Note that a new process that's started alongside already running instances of the same process will be independent from the others. In addition, Start may return a non-null Process with its HasExited property already set to true. In this case, the started process may have activated an existing instance of itself and then exited.
MorganIGuess
MorganIGuessOP13mo ago
So process.start cannot return this process essentially I see So are there different ways for the video player to automatically close after it's done playing> ? You can send me articles you find of any methods that work like that
wasabi
wasabi13mo ago
Different video players can behave however they want. All you're doing is telling Windows to launch whatever you have configured for MP4 files
MorganIGuess
MorganIGuessOP13mo ago
Yeah so then do I have to restrict it to only one media player (ex: windows media player) for it to automatically close in the end?
wasabi
wasabi13mo ago
Does Windows Media Player close itself when you launch it? That's a question for Windows Media Player. Does it provide a command line argument to do so? You'll have to consult with Windows Media Player.
MorganIGuess
MorganIGuessOP13mo ago
No the user needs to manually press the X I dont think so Im not running media player in the forms im executing it from the source's bin folder itself so i dont think the media player class commands work
Jester
Jester13mo ago
@Jesse x Walt is the best ship if you can start the media player process you choose directly. get a handle to its window. so you can PInvoke PostMessage to send a WM_CLOSE event to close it. which does the same thing as pressing X on the window
MorganIGuess
MorganIGuessOP13mo ago
Can you send me examples featuring this in code? And provide the windows article to it I'd love to look further into your suggestion
Jester
Jester13mo ago
Process.MainWindowHandle Property (System.Diagnostics)
Gets the window handle of the main window of the associated process.
PostMessageW function (winuser.h) - Win32 apps
Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message. (Unicode)
DllImportAttribute Class (System.Runtime.InteropServices)
Indicates that the attributed method is exposed by an unmanaged dynamic-link library (DLL) as a static entry point.
MorganIGuess
MorganIGuessOP13mo ago
Thank youu
Want results from more Discord servers?
Add your server