Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Background process updating values in a datagrid
Message
De
30/09/2013 13:44:45
 
 
À
28/09/2013 06:57:41
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01584125
Message ID:
01584467
Vues:
34
>>Thanks Viv,
>>I think I have it working now.
>
>Just for the heck of it - a Task based version which gets rid of BackgroundWorker altogether and, because it's parallel, should be a whole lot faster:
        private void BtnTask_OnClick(object sender, RoutedEventArgs e)
>        {
>            btnTask.IsEnabled = btnEmail.IsEnabled = false;
>            txtInfo.Text = string.Empty;
>
>            //Dummy list of Primary Keys
>            var emailPKs = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
>            progressBar.Maximum = emailPKs.Count;
>            progressBar.Minimum = 0;
>
>            List<Task> tasks = new List<Task>();
>            var ui = TaskScheduler.FromCurrentSynchronizationContext();
>
>            foreach (var id in emailPKs)
>            {
>                var send = Task.Factory.StartNew(() =>
>                    {
>                    return SendEmail(id);
>                });
>                tasks.Add(send);
>
>                var display = send.ContinueWith(result =>
>                {
>                    txtInfo.Text += String.Format("Email to {0} - {1}{2}", send.Result.EmailId,
>                                                       send.Result.Status.ToString(), Environment.NewLine);
>                    progressBar.Value++ ;
>                }, ui)
>                ;
>            }
>
>
>            Task.Factory.ContinueWhenAll(tasks.ToArray(), result =>
>            {
>                txtInfo.Text += "Complete." + Environment.NewLine;
>                btnTask.IsEnabled = btnEmail.IsEnabled = true;
>                progressBar.Value = progressBar.Maximum;
>            }, CancellationToken.None, TaskContinuationOptions.None, ui);
>
>        }
>Snag is SMTP (if that's what you are using) may not be able to handle being hit from all directions :-{

Hmm, interesting stuff Viv. I may make use of it elsewhere for updating a table with 4000 odd updates, Unless that might be a problem too.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform