Click here to Skip to main content
15,887,135 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: FlowDocument - different coloured text in a word Pin
RugbyLeague30-Nov-12 8:49
RugbyLeague30-Nov-12 8:49 
QuestionGrid.ColumnDefinition.setvalue Pin
caradri28-Nov-12 3:06
caradri28-Nov-12 3:06 
AnswerRe: Grid.ColumnDefinition.setvalue Pin
Matt T Heffron28-Nov-12 9:05
professionalMatt T Heffron28-Nov-12 9:05 
GeneralRe: Grid.ColumnDefinition.setvalue Pin
caradri28-Nov-12 20:12
caradri28-Nov-12 20:12 
QuestionGrid Pin
Ehsan Mashkouty28-Nov-12 0:01
Ehsan Mashkouty28-Nov-12 0:01 
QuestionSet Backgroundcolor when CheckBox in TreeView is checked Pin
Member 963452827-Nov-12 23:43
Member 963452827-Nov-12 23:43 
QuestionWPF Grid Splitter Problem Pin
Kevin Marois27-Nov-12 16:27
professionalKevin Marois27-Nov-12 16:27 
QuestionWPF Dispatch.Invoke/BeginInvoke deadlock? Pin
devvvy26-Nov-12 19:30
devvvy26-Nov-12 19:30 
Here's one tough question - I am suspecting Dispatcher deadlock, thus freezing the UI (after I click SaveItems button some number of times).

The following event handler "OnItemsReloaded" is triggered async from another thread ("LoadItems" thread - which holds a lock on an object "ItemsSyncRoot". Another thread ("SaveItems" thread) also competes to lock on to this object.
(So yes, LoadItems thread and SaveItems thread contending for same lock)

Here's the EMPTY Dispatcher.Invoke (Triggered by "LoadItems" thread - a background thread):
<br />
private void OnItemsReloaded(object sender, EventArgs e)<br />
{<br />
		SchedulesGrid.Dispatcher.Invoke(<br />
				System.Windows.Threading.DispatcherPriority.Normal,<br />
					  new Action(<br />
						delegate()<br />
						{<br />
							// EMPTY HERE! (For debugging purpose, I removed everything here)<br />
						}<br />
				));<br />
	<br />
	return;<br />
}<br />


If I change above from "Invoke" to "BeginInvoke" - UI no longer freeze! Question is why. (Please note for debugging purpose, event handler Dispatcher delegate is empty! [So no lock in Dispatch.Invoke delegate!]
[SAME, UI don't freeze if I put a "return" before "Dispatcher" invoke!?]

I futher attempted to nail down the scope further by:
(a) Attached Visual Studio debugger to the running/freezed UI - then from Intellitrace, "Breakall"- which reveals that execution of a "Background" thread freeze on attempting to lock(ItemsSyncRoot). Since this is a background thread ("SaveItems" thread) which attempted to lock(ItemsSyncRoot) - this does NOT explains why UI freezed!

(b) Windbg - !syncblk,) then !clrstack - which pointed me to the [Dispatcher.Invoke] as stated above! But what's confusing is, I don't see why an "Empty Dispatcher Invoke" can lead to UI freezing up.

Note that from !syncblk Info=64. I used that in !clrstack command (Is this right?)
<br />
0:210> .loadby sos clr		<-- This is to load SOS managed code debugger extension (From same dir as CLR)<br />
0:210> !syncblk				<-- List locks, note Info=64. Next command uses this thread ID 64 to retrieve CLR stack of thread 64.<br />
Index SyncBlock MonitorHeld Recursion Owning Thread Info  SyncBlock Owner<br />
  425 11f0d280            3         1 07136b68 1938  64   0279d498 ItemsSyncRoot<br />
-----------------------------<br />
Total           425<br />
CCW             7<br />
RCW             8<br />
ComClassFactory 0<br />
Free            20<br />
<br />
0:210> ~64e!clrstack		<-- see what's thread 64 is doing<br />
OS Thread Id: 0x1938 (64)<br />
Child SP IP       Call Site<br />
0e44d7e0 77e200fd [HelperMethodFrame_1OBJ: 0e44d7e0] System.Threading.WaitHandle.WaitOneNative(System.Runtime.InteropServices.SafeHandle, UInt32, Boolean, Boolean)<br />
0e44d888 6354b5ef System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle, Int64, Boolean, Boolean)*** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\246f1a5abb686b9dcdf22d3505b08cea\mscorlib.ni.dll<br />
<br />
0e44d8a4 6352b1ee System.Threading.WaitHandle.WaitOne(System.TimeSpan, Boolean)<br />
0e44d8c4 65addfc1 System.Windows.Threading.DispatcherOperation+DispatcherOperationEvent.WaitOne()*** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_32\WindowsBase\d17606e813f01376bd0def23726ecc62\WindowsBase.ni.dll<br />
<br />
0e44d8f4 65adda7a System.Windows.Threading.DispatcherOperation.Wait(System.TimeSpan)<br />
0e44d90c 65aee0aa System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)<br />
0e44d954 65cc8d3d System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority, System.Delegate)<br />
<br />
... [What the hell a empty Dispatcher.Invoke caused UI to freeze up!?]<br />
0e44d970 005763ee ...OnItemsReloaded(System.Object, System.EventArgs)*** WARNING: Unable to verify checksum for ...<br />
...<br />
<br />
0e44e6f8 6354ae5b System.Threading.ThreadHelper.ThreadStart_Context(System.Object)<br />
0e44e708 634d7ff4 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)<br />
0e44e72c 634d7f34 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)<br />
0e44e748 6354ade8 System.Threading.ThreadHelper.ThreadStart()<br />
0e44e96c 671c21db [GCFrame: 0e44e96c] <br />
0e44ec30 671c21db [DebuggerU2MCatchHandlerFrame: 0e44ec30] <br />


Note that after I changed Dispatcher.Invoke to Dispatcher.BeginInvoke the problem basically resolved. I just want to know why it happenned. (If WPF Dispatcher framework... any issue...)

I also used Steve Johnson's SOSEX debugger - scan indicated Absence of deadlock!

Confused.

REF 1:
http://ewulf84.blogspot.hk/2011/12/using-syncblk-to-debug-hung-operation.html
http://stackoverflow.com/questions/508398/detecting-deadlocks-in-a-c-sharp-application
http://msdn.microsoft.com/en-us/magazine/cc163618.aspx#S4
REF 2 - WinDbg: http://msdn.microsoft.com/en-us/windows/hardware/gg463009/
REF 3 - WinDbg cheat sheet: http://geekswithblogs.net/.NETonMyMind/archive/2006/03/14/72262.aspx
REF 4 - Steve Johnson SOSEX Debugger extension: http://www.informit.com/articles/article.aspx?p=1583957 and http://www.stevestechspot.com/SOSEXV40NowAvailable.aspx)
dev


modified 27-Nov-12 1:58am.

Answer[SOLN FOUND] - it is NOT that Dispatcher.Invoke buggy! Pin
devvvy29-Nov-12 14:15
devvvy29-Nov-12 14:15 
GeneralRe: [SOLN FOUND] - it is NOT that Dispatcher.Invoke buggy! Pin
Paulo Zemek23-Jan-13 6:41
mvaPaulo Zemek23-Jan-13 6:41 
QuestionChange [EnableClientAccess(RequiresSecureEndpoint = true)] based on config Pin
Adam_Dev20-Nov-12 22:34
Adam_Dev20-Nov-12 22:34 
QuestionCommand Binding Pin
Andy_L_J19-Nov-12 10:51
Andy_L_J19-Nov-12 10:51 
AnswerRe: Command Binding Pin
SledgeHammer0119-Nov-12 11:14
SledgeHammer0119-Nov-12 11:14 
GeneralRe: Command Binding Pin
Andy_L_J19-Nov-12 11:36
Andy_L_J19-Nov-12 11:36 
GeneralRe: Command Binding Pin
Mycroft Holmes19-Nov-12 11:51
professionalMycroft Holmes19-Nov-12 11:51 
GeneralRe: Command Binding Pin
Andy_L_J19-Nov-12 12:14
Andy_L_J19-Nov-12 12:14 
GeneralRe: Command Binding Pin
Mycroft Holmes19-Nov-12 13:22
professionalMycroft Holmes19-Nov-12 13:22 
GeneralRe: Command Binding Pin
SledgeHammer0119-Nov-12 12:14
SledgeHammer0119-Nov-12 12:14 
GeneralRe: Command Binding Pin
Mycroft Holmes19-Nov-12 13:26
professionalMycroft Holmes19-Nov-12 13:26 
GeneralRe: Command Binding Pin
Wayne Gaylard20-Nov-12 3:29
professionalWayne Gaylard20-Nov-12 3:29 
GeneralRe: Command Binding Pin
SledgeHammer0120-Nov-12 6:42
SledgeHammer0120-Nov-12 6:42 
AnswerRe: Command Binding Pin
Pete O'Hanlon22-Nov-12 22:41
mvePete O'Hanlon22-Nov-12 22:41 
GeneralRe: Command Binding Pin
Andy_L_J23-Nov-12 1:48
Andy_L_J23-Nov-12 1:48 
QuestionWPF Components For WinForm Pin
alirezamansoori13-Nov-12 5:26
alirezamansoori13-Nov-12 5:26 
AnswerRe: WPF Components For WinForm Pin
Pete O'Hanlon13-Nov-12 7:56
mvePete O'Hanlon13-Nov-12 7:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.