.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

Raising PropertyChanged on a background thread.

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :WPF
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?  

View Complete Post

More Related Resource Links

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

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  

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.

Raising an Event in another thread from a Thread



I have a Polling thread which runs an infinite loop . and I have another thread(business) which is invoked by the UI thread based on user actions.

I need to raise an event in the polling thread from the business thread so that at the begining of the business thread (which is created  by

the UI thread bcause of a user action - say Button click - ) the event is raised and the event needs to be raised inside the Polling thread which is executing some complex logic inside a loop  and need to stop all of its operation temperorly so that the business thread can continue its work and after it completes the polling thread can resume its work , I have done the synchronization using the lock state ment but since the logic inside the loop of the polling thread is complex and takes time to complete each iteration , I need to stop the polling threads exection at the exact moment the business thread starts its execution - two threads share some  common hardware devices .


Is there any way to do this in .Net




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

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

TextBlock Text not refreshed after raising PropertyChanged - object instance the same, ToString() re



I am working with an object that handles localized strings.  The object type (LocalizedString) provides the correct localized string in its ToString() method.

I have a view model that exposes a property of type LocalizedString.  When my current thread and ui culture is changed, I raise the property changed event for this property, however the strings in the UI do not get updated.

I narrowed it down some to discover that it stops working after the value has been read from the property once.  If instead of just raising property changed when the culture changes I do this:


LocalizedString temp = MyProperty;
MyProperty = null;
MyProperty = temp; // <-- property changed gets raised in the setter 


It seems to work.  The only difference is that the LocalizedString object instance changed.

Basically I believe what happens is this:  The dependency property (TextBlock.Text in this case) gets notified that the bound value has changed.  It goes and retrieves the property value (LocalizedString object), does a comparison and sees that the previous value and the new value are the same object instance, and stops - does not refresh the

Alternating row background for first column of a report


is there a way to make the first column of a report use the an alternating background color? 

I have the background color set for the entire row however it does not work for the first column if the color is set to an expression.  If I just set it to a color i.e. red it works just fine. If I insert a dummy column to the left it works just fine (but the dummy column does not work, presumably because it is first??).

In the file below only the textbox for part number does not show an alternating background.  All others work correctly.

                    <Textbox Name="PartNumber">

Selected to change the background color of the page



As this site, http://www.borfin.com.tr/genel/Default.aspx, How can I change the background color selected pages.

how to make a css style background image be linked to an image in the resource file


hey guy, i need help in a very troubling matter. I want to make a textbox with a specific style, within this style a set of images as background parts, how can i attach these images to the custom control as whenever i take the .dll file and add it to the toolbar the images do not appear. So i tried to make them as resource files and their property as embedded in .resx file, so how to make the css style background image url to be linked to any of those image.

thanks in advance

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

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