tags:

views:

337

answers:

2

I have a .NET custom control that displays information in a culture dependant way. To improve performance I cache some information inside the control rather than generate it every time. I need to know if the culture has changed so that I can regenerate this internal info as appropriate.

Is there some event I have hook into? Or do I have to just test the culture setting every time I paint to see if it has changed?

A: 

I suspect you could do this by having your code change the culture via a central property that itself does something like raise an event; but be very very careful: static events are a very easy way to keep an insane amount of objects stuck in memory (i.e. GC treats them as alive). If you go for this approach, you might want to look at things like WeakReference...

Marc Gravell
+1  A: 

It seems that there is no event, but Windows does broadcast the WM_SETTINGSCHANGE message to all Forms. You could try detecting it by overriding WndProc (Check this and this for more info).

In that case you don't need to fire a static event, but rather invalidate your static "cache" and continue.

Groo