Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

ASP.NET with 2.0/3.5, Silverlight 2/3/4, WPF, WCF, nHibernet, Javascript, Jquery, Ajax, C#-2.0/3.0, Sql server 2005/2008, MySql 5.1., RIA WCF Service, Entity Framework.
Browse by Tags · View All
.Net 8
SQL 5
Sql Server 3
T SQL 3
linq 3
ORM 2
ORM 2
Browser 2
Silverlight 2
C# 2

Archive · View All
December 2011 9
January 2012 4
July 2012 3
October 2012 1
September 2012 1
August 2012 1
May 2012 1
April 2012 1
March 2012 1
February 2012 1

Using BackgroundWorker with WPF

Mar 27 2012 12:00AM by Viral Sarvaiya   

When one process take so much long time and UI thread needs to stay responsive while process is running, the most common method to place a long running process on a separate thread.

In WPF there are mostly use technique is  Backgroundworker. Backgroundworker is mostly use in multithreading applications.

Here I show a small example of backgroundworker.

In WPF application I call WCF service function directly not asynchronies, so that function take time get response and at that time user can't see what happen. so we have to integrate busyindicater while service call.

Busyindicater comes with WPF extended toolkit.


private void OKButton_Click(object sender, RoutedEventArgs e)
{
MyService myservice = new MyService();
MyServiceResponse Myserviceresponce = new MyServiceResponse();
Myserviceresponce = myservice.CallMyFunction(int Para1, string para2);
}

here when user click to OK Button, CallMyFunction() take so much long time and end user confuse what to do at that time and he/she click more than one time to that button and application will crashed.

so we put busy indicator in our code and calling this function asynchronies with backgroundworker.


<extToolkit:BusyIndicator x:Name="_busyIndicator" >
<Grid>
....
</Grid>
</extToolkit:BusyIndicator>

and in CS page


private void OKButton_Click(object sender, RoutedEventArgs e)
{
_busyIndicator.IsBusy = true;

MyServiceResponse Myserviceresponce = new MyServiceResponse();

BackgroundWorker worker = new BackgroundWorker();
worker.RunWorkerAsync();

//this is where the long running process should go
worker.DoWork += (o, ea) =>
{
MyService myservice = new MyService();
Myserviceresponce = myservice.CallMyFunction(int Para1, string para2);
};

worker.RunWorkerCompleted += (o, ea) =>
{
_busyIndicator.IsBusy = false;

//Continue other statment of this function...
};
}

So this will display busyindicator while service call complete.
Hope this will helps you.
Thanks.


Tags: asynchronies, BackgroundWorkerX busyindicator, Using BackgroundWorker with WPFX WCF, WPFX WPF extended toolkit


Viral Sarvaiya
176 · 1% · 279
2
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"Using BackgroundWorker with WPF" rated 5 out of 5 by 2 readers
Using BackgroundWorker with WPF , 5.0 out of 5 based on 2 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]