Wed, October 4, 2006, 04:36 AM under Windows | Vista
At a talk last week, while demoing the Vista application recovery mechanism, a delegate (no pun intended!) asked me if he could access UI elements (e.g. textbox contents) from the recovery function (i.e. in my sample, the RecoveryIt method).

The stock answer is that in your recovery method you should not be spending too much time doing anything and should make no assumptions for any application state as you have just crashed and hence who knows what is valid and what not. Try and do something that is fairly autonomous.

Having said that, from trial and error, I can tell you that you can write to files (as the sample shows), you can create threads, access private variables (and hence navigate object structures) and even the form's handle is valid.

Note that the method runs on a worker thread (that is donated by the OS in the recovery scenario); it is easily provable by sticking the following line of code in the recovery method:
MessageBox.Show(Thread.CurrentThread.IsBackground.ToString()); //true

So, based on the previous sentence, it is obvious that you cannot touch UI elements from that method (we know that we have to be on the main thread to do that). Even if you try to use Invoke/BeginInvoke, you still won't get very far. The point here is that you should treat the UI as frozen or in other words don't rely on the availability of a message pump...

Also, here is an extract of the bullet points from the slide that accompanies my demo:
+ Recovery routine called after data collection
--+ Application’s code attempts to recover user work
----+ Flush to disk, repair on next run of application
----+ Repair data in memory, save to disk

Hope this helps.
Comments are closed.