views:

33

answers:

1

Probably a simple question, but my brain isn't working today.

I am writing a small powershell script to do various tasks. These tasks are logically grouped into tabs, using a WPF TabControl.

A couple of the tabs do some checks to compare local file dates with server file dates, which takes a bit of time. (Only a few seconds, admittedly, but it means the tab doesn't render until the file version dates have been found.)

So - when the script is run, it opens (quickly) and displays the first tab. I then use the following to generate the content for the rest of the tabs on the fly when each tab is selected:

$Tabs = $d.FindName('Tabs')
$Tabs.Add_SelectionChanged({ GenerateContent ($Tabs.SelectedItem).Header})

So far, so good, but as it stands when you select one of these tabs it appears to hang while my script is getting the info it needs.

What I want it to do is to switch to the tab immediately, and then generate a "Please wait.." while it is getting the info, and then refresh the page with the info I need.

Can anyone suggest a good way of doing this?

Ta,

Ben

+2  A: 

BackgroundWorker - What you need is to do processing of running the script on a separate thread so your UI thread is free and you can show the 'Please wait...' message. When the execution is complete you need to update the UI about it.

Please refer, http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

bjoshi