Articles → Silverlight → Dispatcher Object In Silverlight

Dispatcher Object In Silverlight






Application Execution







Elaboration




<Grid x:Name="LayoutRoot" Background="White">
	<TextBlock x:Name="SampleBlock"></TextBlock>
</Grid>




BackgroundWorker _BackgroundWorker = new BackgroundWorker();
_BackgroundWorker.DoWork += new DoWorkEventHandler(_BackgroundWorker_DoWork);
_BackgroundWorker.RunWorkerAsync();

void _BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
  //  Doing some time consuming task
}






void _BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
  //  Doing some time consuming task
  SampleBlock.Text = "Test Content";
}







Solution





Syntax


this.Dispatcher.BeginInvoke(Delegate d, params Object[] args);



Elaboration




private delegate void AddTextDelegate();
void _BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
  //  Doing some time consuming task            
  this.Dispatcher.BeginInvoke(new AddTextDelegate(ChangeText));
}

private void ChangeText() {
  SampleBlock.Text = "Test Content";
}







Summary





Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, December 27, 2011

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250