[英]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:创建两个线程:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.