.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

WPF: How to interact between UI thread and background thread?

Posted By:      Posted Date: September 10, 2010    Points: 0   Category :WPF
our application needs us to do some heavy work on background thread. however, sometimes the background thread work needs user input to make some decision during the middle process. so we need to back the UI thread to get user input and then back the background thread to continue finish the heavy work. Is there example to show us how to interact bewtween UI thread and background thread? thanks, Jane  

View Complete Post

More Related Resource Links

Raising PropertyChanged on a background thread.

What's the official word from Microsoft on raising the PropertyChanged event on a background thread for a property that's bound to a WPF gui? A couple blogs/sites say that the event is automatically dispatched to the UI thread. I am able to verify this in my own my own tests. I can bind to a property on a view model and then set the property on a background thread without issues. I am able to verify that the property setter is called on a background thread; yet, the UI updates without issues. An example property:   private Brush _background; public Brush Background { get { if (this ._background == null ) { this ._background = Brushes.Blue; } return this ._background; } set { if (this ._background != null ) { Debug.WriteLine(Application.Current.Dispatcher.CheckAccess() ? "On UI Thread" : "On Background Thread" ); this ._background = value; this .OnPropertyChanged("Background" ); } } } If I set this property on a background thread, all backgrounds on controls bound to this property will change without problems. Any official word on this behavior?  

Background Thread + Impersonation + Termination


I have an ASP.NET 2.0 web application that is running in Windows Impersonation Mode...

Where the web site is configured as:

- Disable anonymous access

- and web.config

<authentication mode="Windows"/>
<identity impersonate="true"/>
      <allow users="DOMX\USER1"/>
      <allow users="DOMX\USER2"/>
      <allow users="DOMX\USER3"/>
      <allow users="DOMX\USER4"/>
      <deny users="?"/>
      <deny users="*"/>

This application needs to execute a potentially time consuming set of actions.  I had a couple of questions about using a background thread...

Question 1:   If I launch a background thread in the code behind... will that thread be terminated when the web application timesout?

Question 2:  If I decide to utilize a separate process (i.e. using System.Diagnostics.

How to pause resume Background Worker Thread?


We are working on a VB.Net window based application and we are using Visual Studio 2010 Professional.

In our application during the execution process we have used Background Worker thread and user have the option of cancelling the execution only.

Now we came across a situation that if user wants to pause the execution process then how we can pause the background worker thread so that it can be resumed on resuming the execution by the user?



Premjeet Singh

Regards, Premjeet Singh

Handling API events in a background thread



I am in the planning stages for developing a VB.Net class (I am using VS 2008) that is to obtain data via an API provided by a COM object (AxInterop.TWSLib) making requests to an Internet server. The API provides data via events. The class should do its work on a separate thread; it takes several seconds (sometimes up to ~10) to collect the desired data. One should be able to instantiate several instances of the class in order to collect data in parallel. The class would be given a reference to the TWSLib object when its constructor is called, as well as several parameters. There needs to be a way for the class to provide results, preferably in the form of a generic list.

I have succeeded creating multithreads using the backgroundworker approach. From what I have read, though, that does not appear to be the appropriate approach when the background thread is supposed to wait for events to handle. I have not tackled more advanced multithreading approaches. Studying VS 2008 documentation on Threading, ThreadPool, delegates, etc. has not yet given me an idea how to design a class that handles those API event

Control.Invoke must be used to interact with controls created on a separate thread.


I am making a stock taking application in a smart device projec tin Visual Studio 2010. What i want to do is create a thread for when i want to update the database(csv file) and use a status control to show the user what is happening ("connecting", "saved", "error") etc.


However when i try to call a function from within my save method whcih is running on a thread i get a Control.Invoke must be used to interact with controls created on a separate thread error at runtime.

    private void btnUpdateStock_Click(object sender, EventArgs e)
      if (this.txtStock.ReadOnly == false && notSaving)
        Product p = dataManager.getCurrentProduct();
        p.unitsInStock = Int32.Parse(this.txtStock.Text);

        Thread saveThread = new Thread(new ThreadStart(saveItems));


    public void saveItems()

While processing large cubes, various file system errors: "the background thread running lazy writer



We consistently get these I/O errors when processing large OLAP databases.  After a reboot, I can usually get a database to process a few times, but then suddenly reprocessing will fail with errors similar to the one shown below, when nothing changed (no data or structure changes).  The specific file(s) it reports are always different.  Also, sometimes it crashes the msmdsrv.exe process, which seems to intermittently affect other server functions as well (killing the ability to RDP into the server, or the ability to open Event Viewer).


<error message>

File system error: The background thread running lazy writer encountered an I/O error.
Physical file: \\?\D:\OLAPData\SSAS1\SA1.166.db\SA1 Data Source View 1.238.cub\Fact Subject.231.det\Fact Subject.221.prt\271.Aspect.Source Key.fact.map.hdr.
Logical file: .
File system error: The following error occurred while writing to the file 'LazyWriter Stream':
Insufficient system resources exist to complete the requested service. .
File system error: The background thread running lazy writer encountered an I/O error.
Physical file: \\?\D:\OLAPData\SSAS1\SA1.166.db\SA1 Data

Thread Performance: Resource Contention Concurrency Profiling in Visual Studio 2010


Visual Studio 2010 includes new resource contention profiling features that help detect concurrency contention among threads. We walk through a profiling investigation to demonstrate how you can pinpoint and fix resource contention problems in your code.

Maxim Goldin

MSDN Magazine June 2010

Thread Diagnostics: Performance Tuning with The Concurrency Visualizer in Visual Studio 2010


Understanding performance bottlenecks in multithreaded apps used to require significant instrumentation and analysis by expert developers. The Concurrency Visualizer in Visual Studio 2010 significantly reduces the burden of parallel performance analysis.

Hazim Shafi

MSDN Magazine March 2010

CLR Inside Out: Thread Management In The CLR


Getting the performance you want in concurrent applications is not as straightforward as you might think. See how common threading issues can affect your application.

Erika Fuentes and Eric Eilebrecht

MSDN Magazine December 2008

Editor's Note: new Thread(ReadEditorsNote).Start(); yourAttention.WaitOne();


Introducing the issue, Howard Dierking points out that you can't simply parallelize your code blindly if you expect to truly reap the benefits that parallelism promises.

Howard Dierking

MSDN Magazine October 2008

Pooled Threads: Improve Scalability With New Thread Pool APIs


The new threadpool APIs in Windows Vista and in the upcoming Windows Server 2008 provide advances that even native Windows developers can benefit from.

Robert Saccone

MSDN Magazine October 2007

Concurrent Affairs: Build a Richer Thread Synchronization Lock


In my last column, I showed the various thread synchronization mechanisms employed by the Microsoft® . NET Framework (see Concurrent Affairs: Performance-Conscious Thread Synchronization). I then examined the performance characteristics of all these mechanisms and determined that the Interlocked methods performed the best because the calling thread never has to transition to kernel mode.

Jeffrey Richter

MSDN Magazine March 2006

Concurrent Affairs: Performance-Conscious Thread Synchronization


In my career, I have architected and implemented many thread synchronization techniques. This has provided me with a lot of experience that has shaped the way I now think about thread synchronization problems.

Jeffrey Richter

MSDN Magazine October 2005

Basic Instincts: Thread Synchronization


My last three Basic Instincts columns have examined techniques for using asynchronous delegates and creating secondary threads. Those columns demonstrated how to introduce multithreaded behavior into your applications.

Ted Pattison

MSDN Magazine September 2004

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend