-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try fix WriteableBitmap hangs when source bitmap is rendered on other thread #4425
base: main
Are you sure you want to change the base?
Try fix WriteableBitmap hangs when source bitmap is rendered on other thread #4425
Conversation
@lindexi can you please be more descriptive in the PR, what is the bug and how does your PR fix it? |
@miloush Yes, I will add |
209af94
to
2f3bbfe
Compare
@lindexi - Could you please rebase this PR and resolve the build error? I attempted to do it myself, but I don't have the necessary access. |
2f3bbfe
to
15b303f
Compare
@Kuldeep-MS Thank you and I rebase the PR. |
@lindexi The build fails due to "Void" instead of "void" in method signatures:
I also don't like the |
15b303f
to
b8edb20
Compare
Fixes Issue #4396
Description
See #4396
Why
Why the background task will dead lock? Because the background task will get the lock in
WriteableBitmap.InitFromBitmapSource
method.And the
source
is a TransformedBitmap which was created inProcessImageAsync
method and running in background task.But the
source.SyncObject
will be used in main thread when Render.The main thread will use the same SyncObject in BitmapSource.UpdateBitmapSourceResource
The main thread will waitting the
_syncObject
which be used in background task inWriteableBitmap.InitFromBitmapSource
method.But the background task now waitting the main thread in
MediaSystem.Startup
. So the main thread wait background task to release the_syncObject
lock and the background task wait main thread.How
By splitting the original Unlock method, we are able to enter the InitFromBitmapSource method when creating a WriteableBitmap object in the background thread without having to wait for the main thread to complete and release the lock. This allows the _syncObject lock to be released as quickly as possible when creating a WriteableBitmap object in the background thread. Since the lock is released before the background thread enters waiting for the main thread, the main thread can safely wait for the lock. The main thread will not wait for each other with the background thread.
Customer Impact
Regression
Testing
Demo test: https://github.com/lindexi/lindexi_gd/tree/82c1dc09816d7a15214a167cae78f215a3393d6c/BitmapSourceTest
Risk