db4o Developer Community
Developer Community db4o open source object database, native to Java and .NET
Register   |  Login
  Search
  • Forums
  • Documentation
  • Resources
  • Downloads
  • Blogs
  • About
Unanswered Active Topics Forums
Forums > English Forums > db4o User Forum
WPF. Different threads error without using threads
Last Post 07 Sep 2009 11:24 PM by ryumkin. 3 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
ryumkin
New Member
New Member
ryumkin

--
25 Aug 2009 08:34 AM  

I'm not using threads in my app, but I receive an error "Cannot use a DependencyObject that belongs to a different thread than its parent Freezable.", when I'm trying to do the following:

namespace WpfApplication1
{
  public class GrObject
  {
    public Rect Rect { get; set; }
    public Pen Pen { get; set; }
    public void draw(DrawingContext dc)
    {
      dc.DrawRectangle(null, Pen, Rect);
    }
  }
  public partial class Window1 : Window
  {
    IObjectContainer db;
    public Window1()
    {
      InitializeComponent();
      db = Db4oFactory.OpenFile("c:\\temp.db4o");
      try
      {
        GrObject o = new GrObject();
        o.Rect = new Rect(new Point(10, 10), new Size(300, 200));
        o.Pen = new Pen(Brushes.Red, 5);
        db.Store(o);
      }
      catch (Exception ee) { }
      finally
      {
        db.Close(); // Storing the data
      }
      db = Db4oFactory.OpenFile("c:\\temp.db4o"); // Opening again
    }
    protected override void OnRender(DrawingContext dc)
    {
      base.OnRender(dc);
      IEnumerable<GrObject> p = from GrObject o in db select o;
      foreach (GrObject o in p)
      {
        o.draw(dc);
      }
    }
    ~Window1()
    {
      db.Close();
    }
  }
}

ryumkin
New Member
New Member
ryumkin

--
05 Sep 2009 01:57 AM  
up. Somebody help me!
gamlerhart
Basic Member
Basic Member
Posts:345
gamlerhart

--
07 Sep 2009 12:42 PM  

You're problem is almost certainly that you try to store instances of WPF-classes. (For example the Brushes.Red-instance). All WPF and Winforms-classes are closly coupled to the rendering-pipeline. So therefore instances of UI-framework-classes have references to whole rendering-system and the native os-resource (for examples handles). Such classes cann't be stored by db4o. Well db4o will trie but fail.

 So finally to I'm comming to the point: You have to carfully design and choose your domain-model-classes. Avoid any GUI-classes in you domain-model. For example: I'm currently developing a WPF-application myself and i also store UI-related information such as colors. However I don't use the WPF-color-class, but my own Color-Class for storing the information.

ryumkin
New Member
New Member
ryumkin

--
07 Sep 2009 11:24 PM  

Actually I don't think that it's too complicate for db4o to store UI class objects.

I think I find out the problem, but couldn't solve it yet. If I put  the following in GrObject.draw():

 Console.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId+" "+this.Pen.Dispatcher.Thread.ManagedThreadId);

it shows that my Pen is in the different thread! So if I understand right, when I'm querying the data from db4o, complex members returns made in another thread... can someone explain that?

You are not authorized to post a reply.
Forums > English Forums > db4o User Forum

Active Forums 4.2
Close
Copyright ©2000-2010 by Versant Corp.
Privacy Policy