private void addNewVideoToList(Video video) { MyProgressBar progressBar = new MyProgressBar(); progressBar.MinimumSize = progressBars.ImageSize; progressBar.MaximumSize = progressBars.ImageSize; progressBar.Size = progressBars.ImageSize; if (progressBars.Images.IndexOfKey(video.getID()) == -1) { Bitmap progressBarBitmap = new Bitmap(progressBars.ImageSize.Width, progressBars.ImageSize.Height); progressBar.DrawToBitmap(progressBarBitmap, progressBarBounds); VideoListItem item = new VideoListItem(video, ref progressBarBitmap, ref progressBar); item.Font = new Font(lvActiveDownloads.Font, FontStyle.Regular); lvActiveDownloads.Items.Add(item); progressBars.Images.Add(video.getID(), progressBarBitmap); item.ImageKey = video.getID(); Thread update = new Thread(() => updateInfo(item)); update.IsBackground = true; update.Start(); } else { Bitmap progressBarBitmap = (Bitmap)progressBars.Images[video.getID()]; progressBar.DrawToBitmap(progressBarBitmap, progressBarBounds); VideoListItem item = new VideoListItem(video, ref progressBarBitmap, ref progressBar); item.Font = new Font(lvActiveDownloads.Font, FontStyle.Regular); lvActiveDownloads.Items.Add(item); progressBars.Images.Add(video.getID(), progressBarBitmap); item.ImageKey = video.getID(); Thread update = new Thread(() => updateInfo(item)); update.IsBackground = true; update.Start(); } }
private void updatePlaylist(VideoListItem item, string playlistId, string Location, string Format) { Dictionary <string, string> videos = IdAndNameExtractorFromPlaylist.GetIdsAndNames(playlistId); RemovePlaylistSafe(item); startAddingVideosFromPlaylistSafe(videos, Location, Format); if (playlistThreads.ContainsKey(((Video)item.Tag).getID())) { playlistThreads.Remove(((Video)item.Tag).getID()); } }
private void RemovePlaylistSafe(VideoListItem item) { if (lvActiveDownloads.InvokeRequired) { var d = new RemovePlaylistDelegate(RemovePlaylistSafe); lvActiveDownloads.Invoke(d, new object[] { item }); } else { item.Remove(); } }
private void addNewPlaylistToList(string playlistID, string Location, string Format) { if (!videoExists(playlistID)) { VideoListItem item = new VideoListItem(playlistID); item.Font = new Font(lvActiveDownloads.Font, FontStyle.Regular); item.Tag = new Video(playlistID, Location); lvActiveDownloads.Items.Add(item); Thread updatePlaylistThread = new Thread(() => updatePlaylist(item, playlistID, Location, Format)); updatePlaylistThread.IsBackground = true; updatePlaylistThread.Start(); playlistThreads.Add(playlistID, updatePlaylistThread); } }
private void UpdateItemSafe(VideoListItem item) { if (lvActiveDownloads.InvokeRequired) { var d = new UpdateItemDelegate(UpdateItemSafe); lvActiveDownloads.Invoke(d, new object[] { item }); } else { item.SubItems[1].Text = ((Video)item.Tag).getName(); item.SubItems[2].Text = ((Video)item.Tag).getSizeForUpdate(); item.SubItems[4].Text = ((Video)item.Tag).getSpeedForUpdate(); item.SubItems[5].Text = AllUserConfig.languageRM.GetString("status" + ((Video)item.Tag).getStatus()); item.SubItems[6].Text = ((Video)item.Tag).getETAForUpdate(); item.PB.changeValue(((Video)item.Tag).getProgress(), ((Video)item.Tag).getStatus()); item.PB.DrawToBitmap(item.PBBitmap, progressBarBounds); progressBars.Images[progressBars.Images.IndexOfKey(item.ImageKey)] = item.PBBitmap; } }
private void updateInfo(VideoListItem item) { int status = -1; while (true) { UpdateItemSafe(item); Thread.Sleep(1000); status = ((Video)item.Tag).getStatus(); if (status == 0 || status == 6 || status >= 8) { break; } } string ID = ((Video)item.Tag).getID(); while (((Video)item.Tag).getName() == ID && ((Video)item.Tag).getStatus() != 6 && ((Video)item.Tag).getStatus() < 8) { UpdateItemSafe(item); Thread.Sleep(1000); } UpdateItemSafe(item); }
private void updateInfoOnce(VideoListItem item) { UpdateItemSafe(item); }