-
Notifications
You must be signed in to change notification settings - Fork 124
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
need advice in multythread #91
Comments
I have the same problem, i want to draw a writeableBitmap by multiple threads to increase the draw speed, but seem like it cannot work |
Seems wpf have a strict diplomacy in cross thread access, which every call is checked with
first solution need least effort, but not so much general |
after exploring the code, i've found a way: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WriteableBitmapExMultythreadExample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
WriteableBitmap Bitmap;
public MainWindow()
{
InitializeComponent();
var w = 500;
var h = 500;
Bitmap = BitmapFactory.New(w, h);
bmp.Source = Bitmap;
var ctx = Bitmap.GetBitmapContext();
var thr = new Thread(DrawLine); thr.Start(); thr.Join();
//DrawLine();
ctx.Dispose();
//Bitmap.AddDirtyRect(new Int32Rect(0, 0, w, h));
}
public void DrawLine()
{
Bitmap.DrawLineAa(20, 20, 400, 400, Colors.Black, 2);
}
}
} if you call |
Hi,
If i want to use
WriteableBitmapEx
in a multi thread app, which a single thread is responsible for rendering an image in real-time, very much like rendering a game, but not exactly like that. just like one.The problem is the main UI thread is different than rendering thread and i'll get the exception by wpf which says owner thread only can access the bitmap. if I create the
WriteableBitmap
in the render thread, then UI cannot access it and vice versa.I was wondering if you guys have any suggestion for my case?
Thanks
The text was updated successfully, but these errors were encountered: