Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Should be a simple answer to this one.

I have a program where I can select different items on a control. I also want my propertygrid to update with the new selected item.

Only problem is that I am using a WPF propertygrid and it takes a fraction of a sec to update. This update delays the updating of the item control. I have tried Threading, but I get an error in my propertygrid, something about being on a different thread. I could wait until after my item control has refreshed to call the event to update the propertygrid but it would not be a tidy solution for me.

Any ideas on how I could update the propertygrid without having its delay affecting the time to update the item control?
Posted
Updated 25-Jun-11 15:35pm
v3
Comments
Mark Salsbery 25-Jun-11 11:26am    
What is the source of the delay? How are you doing the update - through a binding?

As you are working with WPF, the problem has can be solved using DispatcherSynchronizationContext - as shown in the asnwer to this posting:
http://stackoverflow.com/questions/1949789/using-synchronizationcontext-for-sending-events-back-to-the-ui-for-winforms-or-wp[^]

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Jun-11 19:26pm    
Very good discussion referenced. My 5. I want to note, however, that the real solution offered is to use Dispatcher.BeginInvoke (or Invoke) and not Synchronization Context -- exactly what we advised many times.

Yet another advice -- please see my solution.
--SA
Espen Harlinn 26-Jun-11 4:38am    
Thank you, SAKryukov!
You need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA
 
Share this answer
 
Comments
Espen Harlinn 26-Jun-11 4:44am    
Right, my 5 - System.Windows.Threading.Dispatcher is certainly a mechanism worth consideration.
Sergey Alexandrovich Kryukov 26-Jun-11 11:25am    
Thank you, Espen.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900