Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Back-ground threading on diagram, any suggestion? (Read 1499 times)
GoldyWang
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 34
Joined: May 7th, 2012
Back-ground threading on diagram, any suggestion?
May 10th, 2012 at 4:13am
Print Post  
I want to Add or Remove Nodes in a background thread,, have any sugguestion ?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Back-ground threading on diagram, any suggestion?
Reply #1 - May 10th, 2012 at 4:36am
Print Post  
The control is not thread safe, the background thread will have to use Control.Invoke to delegate the node insertion to the UI thread.

If there's only one background thread, it might be possible to directly add nodes if you set Behavior = Nothing to prevent users from drawing new nodes at the same time. You'll also have to synchronize the operation with event handlers such as NodeClicked if they modify the diagram. If you use this approach, you'll have to test extensively to make sure there aren't some other conflicts with the UI thread.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
GoldyWang
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 34
Joined: May 7th, 2012
Re: Back-ground threading on diagram, any suggestion?
Reply #2 - May 10th, 2012 at 10:42am
Print Post  
Now I try as following, and it seems work now. but hard-working-coding when each function need to be called in thread.

    public class TDiagram : Diagram
    {
        public DiagramView View { get; set; }
        //---------------------------------------------------------------------
        public delegate void TRemoveNodeDelegate(ShapeNode node);
        private TRemoveNodeDelegate m_RemoveNodeDelegate;
        [
        Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        protected TRemoveNodeDelegate RemoveNodeDelegate
        {
            get
            {
                if (m_RemoveNodeDelegate == null)
                    m_RemoveNodeDelegate = new TRemoveNodeDelegate(RemoveNodeCore);
                return m_RemoveNodeDelegate;
            }
        }
        //--------------------------------------------------------------------
        public void RemoveNode(ShapeNode node)
        {
            if (View.InvokeRequired)
                View.Invoke(RemoveNodeDelegate, new object[] { node });
            else
                RemoveNodeCore(node);
        }
        //--------------------------------------------------------------------
        public void RemoveNodeCore(ShapeNode node)
        {
            this.Nodes.Remove(node);
        }

        //---------------------------------------------------------------------
        public delegate void TAddNodeDelegate(ShapeNode node);
        private TAddNodeDelegate m_AddNodeDelegate;
        [
        Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
        ]
        protected TAddNodeDelegate AddNodeDelegate
        {
            get
            {
                if (m_AddNodeDelegate == null)
                    m_AddNodeDelegate = new TAddNodeDelegate(AddNodeCore);
                return m_AddNodeDelegate;
            }
        }
        //--------------------------------------------------------------------
        public void AddNode(ShapeNode node)
        {
            if (View.InvokeRequired)
                View.Invoke(AddNodeDelegate, new object[] { node });
            else
                AddNodeCore(node);
        }
        //--------------------------------------------------------------------
        public void AddNodeCore(ShapeNode node)
        {
            this.Nodes.Add(node);
        }
        //--------------------------------------------------------------------

    }
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint