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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

InvokeRequired on Diagram Model

Thread ID:

Created:

Updated:

Platform:

Replies:

95386 Jul 5,2010 03:22 PM UTC Jul 13,2010 12:06 PM UTC WinForms 3
loading
Tags: Diagram
Mathieu Audet
Asked On July 5, 2010 03:22 PM UTC

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!

Jaffersathick B [Syncfusion]
Replied On 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

Mathieu Audet
Replied On 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

Jaffersathick B [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;