Q: How can I stop BitmapImage, in .NET Windows Presentation Foundation (WPF) from locking the source image file?

 

A: By default BitmapInfo seems to lock the source image file so that you can use the bitmapinfo object and modify or delete the source file at the same (or similar) time. For example, this C# will probably yield a locked image file:

 
var bitmap = new BitmapImage(new Uri(imageFilePath));
// use bitmap…
 

You can get around this locking problem as follows, it’s a little bit more long-winded but it worked for us….

 
var bitmap = new BitmapImage();
var stream = File.OpenRead(imageFilePath);
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.StreamSource = stream;
bitmap.EndInit();
stream.Close();
stream.Dispose();
// Use bitmap…..
 

Related Posts

.NET’s Threading module isn’t the best, it has the look of a model that was designed by the type of software people who like to keep practical multi-threading a good long arm’s length away. It’s workable but sometimes it requires that you jump through hoops to do simple everyday things with threads – like updating a UI element from a non UI thread etc. You may see errors akin to the following:

 

“Must create DependencySource on same Thread as the DependencyObject.”

“This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread.”

To get around this all a .NET developer needs to do is to remember a few ritualistic looking invocations to appease the .NET small gods – but of course I can never remember the details so am recording one such here:

 

To dispatch to the UI from a non-UI thread and non-UI code, use something like the following:

 
using System.Windows;

Application.Current.Dispatcher.Invoke(new Action (() => Thumbnails.Add(thumbnail)));

 

Related Posts

In WPF when you try to assign a bitmap to a property that’s bound to a UI element from a worker thread you may get the following error:

 

“Must create DependencySource on same Thread as the DependencyObject”

 

A simple way around this problem without having to jump through hoops and dispatch to the UI thread is to just freeze the bitmap before assigning it, like this:

 
var bitmap = new BitmapImage(new Uri(CurrentImageFilePath));
bitmap.Freeze();
this.CurrentImage = bitmap;
 

I hope this helps someone who’s stuck with this annoying error!

 

Related Posts

Q: I have created a new skins folder beside my default theme’s skin folder, and placed some images that I want to override into an images sub folder. I have changed the ‘Skin (Images / CSS)’ setting in System -> Configuration -> Design -> Themes to point to my new skins, I have cleared the magento cache about 10 million times, but magento still won’t use my new images, it keeps using the originals…. what do I do?

 

A: This has caught me out once or twice and I have always forgotten about it by the time it happens again! The problem stems from the fact that the theme css file calls in images using a relative path, e.g.:

 
body {background-image:url(‘../images/bg.gif’);}
 

So because the css file that uses your images remains in its original location it will still use your original images, to get it to use your overridden images you must create a css folder in your new skin folder and copy any css files that reference the images into there and clear the cache a further 20 times – hopefully magento will then use your new images!

 

Have a look here for some more details:

 

http://www.magentocommerce.com/boards/viewthread/2445/

 

Related Posts

A Google App Engine cloud application that we have been involved in developing suddenly started getting snowed under by a storm of GAE’s most excellent DeadlineExceededError exceptions.

 

The app never really suffered from this before (unless a rogue task actually took too long that is) but suddenly these errors started happening on a huge number of requests during the module load or _ah/warmup phases, they didn’t even get to run any of our code before they were killed with this most beautiful of error messages. It literally brought the app to its knees…

 

For example, we kept finding stuff like this in the logs:

 
class ‘google.appengine.runtime.DeadlineExceededError’>:
Traceback (most recent call last):
File “/base/data/home/apps/appname/9993.355980156233423494/warmup.py”, line 1, in module>
import appengine_config # Cache by import
File “/base/data/home/apps/appname/9993.355980156233423494/appengine_config.py”, line 27, in module>
….
 

After a little research it seems that this has started happening to loads of GAE users since December 2011, have a look at this thread:

 

http://groups.google.com/group/google-appengine/browse_thread/thread/369a9a76c394c99e/976722e37ad07d0c

 

Loads of annoyed people out there having the same type of problem. The general recommendation was to move to a high replication datastore (rather than master/slave), this move is not always simple however and I believe will incur higher costs!

 

To cut a long story short, our app was dead in the water so we had no choice other than to migrate it to a high replication datastore and hope that this fixed the problem (and hope that the migration didn’t create too many new problems). Once we carried out the migration the DeadlineExceededError excpetions went away, so that was good but we were a bit peeved that our hand was forced in such a way.

 

So I don’t know what google changed but it seems that they want people on high replication or else! Once again we find ourselves seriously questioning whether google app engine is a sutibaly stable platform for deploying real-world apps – the jury is still out…

 

Anyway if you find yourselves with the same problem they you may be headed the HRD way!

 

Related Posts

If you get the following error when using devel’s dvm() in drupal 7 (or indeed, if you see it when not using dvm()):

 
Notice: Undefined variable: output in drupal_var_export()

Then try putting this line into you settings.php file:

 
ini_set(‘error_reporting’, ‘E_ALL ^ E_NOTICE’);
 

It worked for us – thanks to citytree for the fix!

 

Related Posts

The method for Programmatically setting a link field value (see the Link module) in drupal 7 is slightly different from how it was set it in drupal 6. Here is some code for creating a new node and setting its link field (called field_url):

 
$node = new stdClass();
$node->type = ‘website’;
node_object_prepare($node);

$node->title = $site_name;
$node->language = LANGUAGE_NONE;

$node->field_url[$node->language][0]['title'] = “www.ridgesolutions.ie”;
$node->field_url[$node->language][0]['url'] = “www.ridgesolutions.ie”;

node_submit($node);
node_save($node);

 

Related Posts

Here’s a decent article that I found about programmatically creating content in drupal 7:

 

www.group42.ca/creating_and_updating_nodes_programmatically_in_drupal_7

 

Related Posts

  • No Related Post
January 5, 2012

Here is an interesting article about Dries’ vision for Drupal 8:

 

http://www.cio.com.au/article/411440/dries_vision_drupal_8/

 

I like the focus on the editorial experience to help people mange content on-line, drupal is great CMS but it can sometimes be quite difficult for non webbies & techies to effectively manage the content on their drupal websites – in fact this really could have been given more attention in d7 (oh well)!

 

What is also interesting is the recognition that drupal has become more of a web platform than just a CMS alone – that’s how we use it!

 

Related Posts

Recent denials by Nokia that they are about to be taken over by Microsoft brings this line from Yes Minster to my mind:

 

James Hacker: First rule in politics: never believe anything until it’s officially denied.

 

;)

 

Related Posts