Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can a backgroundworker be told to wait?
Message
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Versions des environnements
Environment:
C# 4.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01614173
Message ID:
01614325
Vues:
30
O wow! Sounds promising. I'll try it out and let you know.

Do you still use the bgw, or did you move on to threads, awaits and what have you?


>>To the best of my knowledge it does yes. I use Excel via interop. I think I will refactor my logic so that this situation won't hurt, or put a "wait".
>
>A simple wait might be dangerous if you under-estimate the timing. Maybe a semaphore would work (not tested):
   public class Test
> {
>
> public static ManualResetEvent re = new ManualResetEvent(false);
>
> public void Doit()
> {
> var bg36 = new BackgroundWorker();
> bg36.DoWork += bg36_DoWork;
> bg36.WorkerReportsProgress = true;
> bg36.ProgressChanged += bg36_ProgressChanged;
> bg36.RunWorkerAsync();
>
> }
>
> private void bg36_ProgressChanged(object sender, ProgressChangedEventArgs e)
> {
> if ((string)e.UserState== "save ledgers")
> {
> SaveLedgers();
> Test.re.Set();
> }
> }
>
> public void SaveLedgers()
> {
> }
>
> private void bg36_DoWork(Object sender, DoWorkEventArgs e)
> {
> BackgroundWorker bw = (BackgroundWorker)sender;
> bw.ReportProgress(0,"save ledgers");
> Test.re.WaitOne();
> //Continue
> }
>
> }

If things have the tendency to go your way, do not worry. It won't last. Jules Renard.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform