private static void BackgroundWorkerAsyncRequest_DoWork(object sender, DoWorkEventArgs e) { try { WallpaperBgWorker my_BackgroundWorkerAsync = (WallpaperBgWorker)sender; IdentifyQueryBackground identifiedQuery = null; identifiedQuery = (IdentifyQueryBackground)e.Argument; images.Clear(); getFileList(images, identifiedQuery.directoryPatch); try { Random rnd = new Random(); int currentImage = rnd.Next(0, images.Count); String image = images[currentImage]; Wallpaper.Set(image, identifiedQuery.style); } catch (Exception ex) { } if (my_BackgroundWorkerAsync.CancellationPending) { e.Cancel = true; return; } } catch (Exception ex) { } }
internal static void StopBackgowndWorkProcess() { if (m_BackgroundWorkerAsync.IsBusy == true) { m_BackgroundWorkerAsync.CancelAsync(); m_BackgroundWorkerAsync.Abort(); m_BackgroundWorkerAsync.Dispose(); m_BackgroundWorkerAsync = null; } }
public static void StartBackgowndWorkProcess(IdentifyQueryBackground param) { try { if (m_BackgroundWorkerAsync != null) { m_BackgroundWorkerAsync.CancelAsync(); m_BackgroundWorkerAsync.Abort(); } m_BackgroundWorkerAsync = new WallpaperBgWorker(); m_BackgroundWorkerAsync.WorkerSupportsCancellation = true; m_BackgroundWorkerAsync.DoWork += new DoWorkEventHandler(BackgroundWorkerAsyncRequest_DoWork); m_BackgroundWorkerAsync.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackgroundWorkerAsyncRequest_RunWorkerCompleted); m_BackgroundWorkerAsync.RunWorkerAsync(param); dictionaryBag.TryAdd(m_BackgroundWorkerAsync.Key, m_BackgroundWorkerAsync); } catch (Exception) { } }