Your animations will be hosted in a Storyboard.
- To make the animations run indefinitely, set the Storyboard's RepeatBehavior to Forever.
- To start the animations when you kick off the BackgroundWorker, call the Storyboard.Begin method.
- To stop the animations when the BackgroundWorker finishes, in your RunWorkerCompleted event handler, call the Storyboard.Stop method.
Here's an example:
<Window.Resources>
<Storyboard x:Key="sb" Duration="0:0:2" RepeatBehavior="Forever">
<DoubleAnimation Storyboard.TargetName="l"
Storyboard.TargetProperty="Opacity"
From="1" To="0" AutoReverse="True" />
<ColorAnimation Storyboard.TargetName="l"
Storyboard.TargetProperty="Foreground.Color"
From="HotPink" To="Lime" AutoReverse="True" />
</Storyboard>
</Window.Resources>
<StackPanel>
<Label Name="l" FontSize="72">Oh noes!</Label>
<Button Click="Button_Click">Animate me!</Button>
</StackPanel>
And the Button_Click handler:
private void Button_Click(object sender, RoutedEventArgs e)
{
((Storyboard)(FindResource("sb"))).Begin();
// and kick off your BackgroundWorker
}