WordPress database error: [INSERT, UPDATE command denied to user '51213-2'@'10.10.20.149' for table 'wp_options']
INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES ('_transient_doing_cron', '1715240625.7453680038452148437500', 'yes') ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)


Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372

Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/rest-api/class-wp-rest-server.php on line 1372
{"id":348,"date":"2011-09-24T21:50:46","date_gmt":"2011-09-24T20:50:46","guid":{"rendered":"http:\/\/www.jonathanantoine.com\/?p=348"},"modified":"2015-07-25T12:35:32","modified_gmt":"2015-07-25T10:35:32","slug":"wpf-4-5-part-7-accessing-collections-on-non-ui-threads","status":"publish","type":"post","link":"http:\/\/www.jonathanantoine.com\/2011\/09\/24\/wpf-4-5-part-7-accessing-collections-on-non-ui-threads\/","title":{"rendered":"WPF 4.5 – Part 7 : Accessing collections on non-UI Threads"},"content":{"rendered":"

\"\"<\/a>Here is the seventh (OMG !) post on the WPF 4.5 new features<\/a>. Collections are a part of every<\/span> application and their management is maybe the first thing you learn to deal with in WPF.<\/p>\n

To begin, you put everything on the main(the UI one) thread and it works just fine. After a few time, you realize that it freezes the application UI and that the users usually don’t like it. Then you put the collections creation\/feeding on another Thread to free the UI’s one and you realize that it is not possible because<\/strong> : “This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread”.<\/em><\/p>\n

In this post we will discover that this is over with WPF 4.5 (and that you’ll love it) !<\/p>\n

<\/p>\n

How do we do in WPF 4.0 ?<\/h3>\n

Let’s say that you have an application which display peoples on a list. The loading of the full list is quite long because it requires to go to a database via a WCF services and then to come back with the information.<\/p>\n

In WPF 4.0 you have two different solutions:<\/span><\/p>\n

    \n
  1. Retrieve the data on the UI Thread and wait after every add <\/em>for the UI Thread to update<\/a>. I don’t personnaly like this solution because this a kind of a hack and the interface reactivness remains odd.<\/li>\n
  2. Tell the user to wait, then retrieve the data on a secondary Thread. Pass the information to the UI Thread and creates the list on it.<\/strong> This is usually what I do even if it’s degrade the code readability because it’s more complex to write.<\/li>\n<\/ol>\n

    Here is a an example of this second solution:<\/p>\n

    [csharp]
    \n private void LoadUpPersonsClick(object sender, RoutedEventArgs e)
    \n {
    \n Task.Factory
    \n \/\/Retrieve the persons on another thread.
    \n .StartNew>(RetrieveTheCollection)
    \n .ContinueWith(t =>
    \n {
    \n foreach (var p in t.Result) _persons.Add(p);
    \n },
    \n \/\/Continue on the UI Thread
    \n TaskScheduler.FromCurrentSynchronizationContext());
    \n }<\/p>\n

    public List RetrieveTheCollection()
    \n {
    \n List persons = new List();
    \n for (int i = 0; i < 10; i++)
    \n {
    \n persons.Add(new Person() { Name = "Person " + i, Age = 40 + i % 5 });
    \n }
    \n return persons;
    \n }
    \n[\/csharp]<\/p>\n

    How do we do in WPF 4.5 ?<\/h3>\n

    Life is really easier in WPF 4.5: all you have to do is to to enable the features via the EnableCollectionSynchronization <\/a><\/em>method<\/strong>. For the record, I struggled a lot to find this method which is a static <\/strong>one of the BindingOperations <\/strong><\/em>class.<\/p>\n

    It takes two parameters: the collection on which access across multiple threads will be enabled and a object which will be used as a lock. Easy as this snippet:
    \n[csharp]
    \n\/\/Creates the lock object somewhere
    \nprivate static object _lock = new object();<\/p>\n

    …<\/p>\n

    \/\/Enable the cross acces to this collection elsewhere
    \nBindingOperations.EnableCollectionSynchronization(_persons, _lock);[\/csharp]<\/p>\n

    There is one another overload which takes a CollectionSynchronizationCallback callback and a could-be-null context as additionna parameters. With this one you could decide which synchronisation mechanism to use instead of the default one which is the lock.<\/p>\n

    So as you can imagine, all the synchronisation work is done for you by the framework and the code you will finally end-up to write will be something like that:
    \n[csharp] private void AccessTheCollectionFromANonUIThreadClick(object sender, RoutedEventArgs e)
    \n {
    \n Task.Factory.StartNew(EditTheCollection);
    \n }<\/p>\n

    public void EditTheCollection()
    \n {
    \n for (int i = 0; i < 10; i++)
    \n {
    \n _persons.Add(new Person() { Name = "Person " + i, Age = 20 + i % 5 });
    \n }
    \n }
    \n[\/csharp]<\/p>\n

    It is clearly more readable, easy to understand and to write !<\/p>\n

    As usual, a full project can be found on my Dropbox folder after registration<\/a>.<\/p>\n

    Thanks to the WPF team for this great new feature !<\/strong><\/p>\n

    Regards,<\/p>\n","protected":false},"excerpt":{"rendered":"

    Here is the seventh (OMG !) post on the WPF 4.5 new features. Collections are a part of every application and their management is maybe the first thing you learn to deal with in WPF.…<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,5],"tags":[14,15],"_links":{"self":[{"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/posts\/348"}],"collection":[{"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/comments?post=348"}],"version-history":[{"count":29,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/posts\/348\/revisions"}],"predecessor-version":[{"id":1553,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/posts\/348\/revisions\/1553"}],"wp:attachment":[{"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/media?parent=348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/categories?post=348"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jonathanantoine.com\/wp-json\/wp\/v2\/tags?post=348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}