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.
below is the code using in 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#.
You mustn't check the media player's status in the same thread.
Create two threads:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.