Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Bug: Dispatcher and WriteableBitmap

$
0
0

I think I found a bug. It is a little complicated to set up, but here goes.
Have tested on Windows 8 and 7.

Create new WPF project.
Insert an Image control and name it "ImageControl".
Insert following code:

private WriteableBitmap awesomeData; public MainWindow() { InitializeComponent(); SizeChanged += MainWindow_SizeChanged; Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)SomeMethod); } void SomeMethod() { WriteableBitmap local = awesomeData; local.Lock();

if (local != awesomeData) { MessageBox.Show("Bug!"); Application.Current.Shutdown(); return; } awesomeData.AddDirtyRect(new Int32Rect(0, 0, 1, 1)); awesomeData.Unlock(); Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)SomeMethod); } void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e) { awesomeData = new WriteableBitmap(1, 1, 96, 96, PixelFormats.Bgr32, null); ImageControl.Source = awesomeData; }

Now run the program, and try to maximize/restore it using (WIN)+UP/(WIN)+DOWN shortcuts. It can take some time to trigger.

Now, as far as I understand, events and Dispatcher items are handled on the UI thread.
Therefore both methods MainWindow_SizeChanged and SomeMethod() should execute sequentially.

Apparently they don't, and MainWindow_SizeChanged can run while the UI thread is sleeping/waiting.

Or am I missing something?

Best regards,
Alexei Mihalchuk



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>