简体   繁体   English

如何在 C# windows 应用程序的表单加载事件中的 process.start("notepad.exe") 之前播放 windows 媒体播放器

[英]how to play windows media player before the process.start("notepad.exe") in form load event in C# windows app

i want to call first media player and then notepad in form_load event, but notepad is opening first and media player is playing after the form is fully loaded, how to play media player first and then open notepad.我想在 form_load 事件中调用第一个媒体播放器,然后调用记事本,但是记事本首先打开,并且在表单完全加载后播放媒体播放器,如何先播放媒体播放器然后打开记事本。

below is the code using in form_load.下面是在 form_load 中使用的代码。

   string fileName = Environment.CurrentDirectory + "\\Setting.ini";
        var lines = File.ReadAllLines(fileName);
        foreach (var s in lines)
        {

            string[] split = s.Split(',');
            if (split[0] == "exe")
            {

                this.WindowState = FormWindowState.Maximized;
                Process pro = new Process();
                pro.StartInfo.FileName = split[1] + ".exe";
                pro.Start();
                Screen screen = Screen.FromControl(this);
                if (screen != null && !screen.WorkingArea.IsEmpty)
                {
                    int sizeDiff = this.Size.Width - this.ClientSize.Width;
                    var maxSize = new Size(screen.WorkingArea.Width + sizeDiff, screen.WorkingArea.Height + sizeDiff);
                    this.MaximumSize = maxSize;
                }
                Thread.Sleep(1000 * Convert.ToInt32(split[2]));
                pro.Kill();

            }
            else if (split[0] == "video")
            {

                string[] files = Directory.GetFiles(split[1]);

                axWindowsMediaPlayer1.uiMode = "none";
                axWindowsMediaPlayer1.settings.setMode("loop", true);
                axWindowsMediaPlayer1.settings.autoStart = true;
                WMPLib.IWMPPlaylist playlist = axWindowsMediaPlayer1.playlistCollection.newPlaylist("myplaylist");
                for (int i = 0; i < files.Length; i++)
                {
                    // string fileName = string.Empty;
                    WMPLib.IWMPMedia media;
                    media = axWindowsMediaPlayer1.newMedia(files[i]);
                    playlist.appendItem(media);
                }
                axWindowsMediaPlayer1.currentPlaylist = playlist;

                axWindowsMediaPlayer1.Ctlcontrols.play();
            }
        }

Create a thread for Notepad.为记事本创建一个线程。 Tell this thread to wait media player to run, when media player starts then open notepad.告诉这个线程等待媒体播放器运行,当媒体播放器启动时打开记事本。 You can monitor the applications running with c#.您可以监视使用 c# 运行的应用程序。

You mustn't check the media player's status in the same thread.您不能在同一线程中检查媒体播放器的状态。

Create two threads:创建两个线程:

  1. Keep the notepad thread priority as max保持记事本线程优先级为最大值
  2. Start the second thread only when the first thread has completed its task.仅当第一个线程完成其任务时才启动第二个线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# 为什么 Process.Start("notepad.exe" myFile) 正常工作,而 Process.Start("notepad++.exe" myFile) 不工作 - C# Why does Process.Start("notepad.exe" myFile) is working and Process.Start("notepad++.exe" myFile) is not working 如何在Windows应用程序中以隐藏模式启动notepad.exe? - How to start notepad.exe in hidden mode in windows application? C#Windows服务process.start - c# windows service process.start Process.Start with UseShellExecute 在前一个关闭窗口后无法将 notepad.exe 窗口带到前台 - Process.Start with UseShellExecute fails to bring notepad.exe window to the foreground after a previous close window C# 中的 Windows 媒体播放器播放状态 - Windows media player play states in C# 在Windows XP虚拟机上使用process.start的C#Windows Forms应用程序 - C# windows forms app using process.start on Windows XP Virtual machine C#Process。从另一个在Windows 8/10中不工作的用户开始 - C# Process.Start with another user not working in Windows 8/10 C# Windows-Form-Application Process.Start() 给出“访问被拒绝”错误 - C# Windows-Form-Application Process.Start() Gives "Access is denied" Error 如何将vlc媒体播放器嵌入我的c#windows表单应用程序? - how to embed vlc media player into my c# windows form app? 如何在 C# 中与 Windows Media Player 交互 - How to interact with Windows Media Player in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM