We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

InvokeRequired on Diagram Model

Hi,

I am trying to add node to a diagram inside a thread and it always crashes each time I call the MyDiagram.Model.AnyPropertyOrMethod because there is not a MyDiagram.Model.InvokeRequired that I can use to map a delegate function.

Any suggestions to add a node to a diagram inside a Thread?

Thanks!

3 Replies

JB Jaffersathick B Syncfusion Team July 6, 2010 06:10 AM UTC

Hi Mathieu Audet,

Thank you for your interest in Syncfusion products.

We suggest you to use the “BackgroundWorker” thread to add the node. Please refer the following code snippet:
[CS]

private void button1_Click(object sender, EventArgs e)
{
this.backgroundWorker1.RunWorkerAsync();
}
void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Syncfusion.Windows.Forms.Diagram.Rectangle rec = new Syncfusion.Windows.Forms.Diagram.Rectangle(10, 10, 100, 100);
rec.EditStyle.AllowDelete = false;
this.diagram1.Model.AppendChild(rec);
}




Please refer the following msdn link:

http://msdn.microsoft.com/en-us/library/ms171728%28VS.80%29.aspx

Let me know if it helps.

Regards,
Jaffer


MA Mathieu Audet July 6, 2010 05:32 PM UTC

Hi Jaffer,

In fact I am already using a background worker. In my backgroundWorker1_DoWork() function, I use the following code to add the node:

if (myDiagram.InvokeRequired)
AddNodeDelegate delegateMethod = new AddNodeDelegate(AddNode);
delegateMethod.Invoke();
else
AddNode();

private void AddNode()
{
myDiagram.Model.AppendChild(some Node);
}

But since the myDiagram.Model doesn't have a .InvokeRequired property, it always crashes. I was wondering if there was a workaround to this, because when the backgroundWorker1_RunWorkerCompleted event is fired, the Thread created by the background worker doesn't exist anymore and the main thread retakes the execution, so the code executed inside this bracket is executed by the main thread.

Any solutions?

Thanks in advance

Mathieu


JB Jaffersathick B Syncfusion Team July 13, 2010 12:06 PM UTC

Hi Mathieu,

Sorry for the delay in getting back to you.

We tried the reported issue with in the “RunWorkerCompleted” but the reported issue does not occur. could you try reproducing it in a simple sample and send us the modified sample, so that we could sort out the cause of the issue and provide you a solution.

Regards,
Jaffer

Loader.
Live Chat Icon For mobile
Up arrow icon