@@ -300,6 +300,12 @@ ref lockBufferStride
300
300
/// on the back buffer and request a render pass.
301
301
/// </summary>
302
302
public void Unlock ( )
303
+ {
304
+ UnlockWithoutSubscribeToCommittingBatch ( ) ;
305
+ SubscribeToCommittingBatchAndWritePostscript ( ) ;
306
+ }
307
+
308
+ private Void UnlockWithoutSubscribeToCommittingBatch ( )
303
309
{
304
310
WritePreamble ( ) ;
305
311
@@ -315,16 +321,19 @@ public void Unlock()
315
321
// This makes the back buffer read-only.
316
322
_pBackBufferLock . Dispose ( ) ;
317
323
_pBackBufferLock = null ;
324
+ }
325
+ }
318
326
319
- if ( _hasDirtyRects )
320
- {
321
- SubscribeToCommittingBatch ( ) ;
327
+ private Void SubscribeToCommittingBatchAndWritePostscript ( )
328
+ {
329
+ if ( _hasDirtyRects )
330
+ {
331
+ SubscribeToCommittingBatch ( ) ;
322
332
323
- //
324
- // Notify listeners that we have changed.
325
- //
326
- WritePostscript ( ) ;
327
- }
333
+ //
334
+ // Notify listeners that we have changed.
335
+ //
336
+ WritePostscript ( ) ;
328
337
}
329
338
}
330
339
@@ -723,17 +732,19 @@ BitmapSource source
723
732
724
733
BeginInit ( ) ;
725
734
726
- _syncObject = source . SyncObject ;
727
- lock ( _syncObject )
735
+ // We will change the _syncObject object in Lock()
736
+ var syncObject = _syncObject = source . SyncObject ;
737
+ try
728
738
{
739
+ Monitor . Enter ( syncObject ) ;
729
740
Guid formatGuid = source . Format . Guid ;
730
741
731
742
SafeMILHandle internalPalette = new SafeMILHandle ( ) ;
732
743
if ( source . Format . Palettized )
733
744
{
734
745
internalPalette = source . Palette . InternalPalette ;
735
746
}
736
-
747
+
737
748
HRESULT . Check ( MILSwDoubleBufferedBitmap . Create (
738
749
( uint ) source . PixelWidth , // safe cast
739
750
( uint ) source . PixelHeight , // safe cast
@@ -742,7 +753,7 @@ BitmapSource source
742
753
ref formatGuid ,
743
754
internalPalette ,
744
755
out _pDoubleBufferedBitmap
745
- ) ) ;
756
+ ) ) ;
746
757
747
758
_pDoubleBufferedBitmap . UpdateEstimatedSize (
748
759
GetEstimatedSize ( source . PixelWidth , source . PixelHeight , source . Format ) ) ;
@@ -758,7 +769,17 @@ out _pDoubleBufferedBitmap
758
769
}
759
770
finally
760
771
{
761
- Unlock ( ) ;
772
+ UnlockWithoutSubscribeToCommittingBatch ( ) ;
773
+ Monitor . Exit ( syncObject ) ;
774
+ }
775
+
776
+ SubscribeToCommittingBatchAndWritePostscript ( ) ;
777
+ }
778
+ finally
779
+ {
780
+ if ( Monitor . IsEntered ( syncObject ) )
781
+ {
782
+ Monitor . Exit ( syncObject ) ;
762
783
}
763
784
}
764
785
0 commit comments