slow filling visio group shape in c# from secondary thread

O

Oleg

I have to change fillforegnd property of a grouped shape on a visio control
from c#.

If I do this from main application thread (button1_Click) then changes
appears on visio control almost immedeatelly.
If i do this from secondary thread (button2_Click) then shape fills very
slowly, part by part.

Why does this happen and how I can fix this?
I have to change fillforegnd property from secondary thread.

Code:
public partial class Form1 : Form
{
private Shape wsShape;

public Form1()
{
InitializeComponent();
axDrawingControl1.Src = @"d:\test_schema2.vsd";
Shape vs =
axDrawingControl1.Document.Pages[1].Shapes.ContainingShape;
for (int i = 1; i <= vs.Shapes.Count; i++)
if (getPropValueStr(vs.Shapes[i], "type") == "workstation")
wsShape = vs.Shapes[i];
}

private string getPropValueStr(Shape vs, string prop)
{
string value = "";
if (vs.get_CellExists("Prop." + prop, 0) != 0)
{
value = vs.get_Cells("Prop." +
prop).get_ResultStr(Microsoft.Office.Interop.Visio.VisUnitCodes.visUnitsString);
if (value == "0,0000") value = "";
}
return value;
}

private void button1_Click(object sender, EventArgs e)
{
fill();
}

private void button2_Click(object sender, EventArgs e)
{
Thread newT = new Thread(new ThreadStart(fill));
newT.Start();
}

private void fill()
{
if ((wsShape != null))
if ((wsShape.Type ==
(short)Microsoft.Office.Interop.Visio.VisShapeTypes.visTypeGroup))
for (int i = 1; i <= wsShape.Shapes.Count; i++)
wsShape.Shapes[i].get_Cells("FillForegnd").FormulaU
= "RGB(255,0,0)";
else
wsShape.get_Cells("FillForegnd").FormulaU =
"RGB(255,0,0)";
}
}
 
X

xiyuantang

Try this code:


public partial class Form1 : Form
{
private Shape wsShape;
private delegate void FillColorEventHandler();
private FillColorEventHandler fillColor;
public Form1()
{
InitializeComponent();
this.fillColor = new FillColorEventHandler(fill)
axDrawingControl1.Src = @"d:\test_schema2.vsd";
Shape vs =
axDrawingControl1.Document.Pages[1].Shapes.ContainingShape;
for (int i = 1; i <= vs.Shapes.Count; i++)
if (getPropValueStr(vs.Shapes, "type") == "workstation")
wsShape = vs.Shapes;
}

private string getPropValueStr(Shape vs, string prop)
{
string value = "";
if (vs.get_CellExists("Prop." + prop, 0) != 0)
{
value = vs.get_Cells("Prop." +
prop).get_ResultStr(Microsoft.Office.Interop.Visio.VisUnitCodes.visUnitsString);
if (value == "0,0000") value = "";
}
return value;
}

private void button1_Click(object sender, EventArgs e)
{
fill();
}

private void button2_Click(object sender, EventArgs e)
{
Thread newT = new Thread(new ThreadStart(OnFillColorFunction));
newT.Start();
}
private void OnFillColorFunction()
{
this.Invoke(this.fillColor)
}
private void fill()
{
if ((wsShape != null))
if ((wsShape.Type ==
(short)Microsoft.Office.Interop.Visio.VisShapeTypes.visTypeGroup))
for (int i = 1; i <= wsShape.Shapes.Count; i++)
wsShape.Shapes.get_Cells("FillForegnd").FormulaU
= "RGB(255,0,0)";
else
wsShape.get_Cells("FillForegnd").FormulaU =
"RGB(255,0,0)";
}
}


Oleg said:
I have to change fillforegnd property of a grouped shape on a visio control
from c#.

If I do this from main application thread (button1_Click) then changes
appears on visio control almost immedeatelly.
If i do this from secondary thread (button2_Click) then shape fills very
slowly, part by part.

Why does this happen and how I can fix this?
I have to change fillforegnd property from secondary thread.

Code:
public partial class Form1 : Form
{
private Shape wsShape;

public Form1()
{
InitializeComponent();
axDrawingControl1.Src = @"d:\test_schema2.vsd";
Shape vs =
axDrawingControl1.Document.Pages[1].Shapes.ContainingShape;
for (int i = 1; i <= vs.Shapes.Count; i++)
if (getPropValueStr(vs.Shapes[i], "type") == "workstation")
wsShape = vs.Shapes[i];
}

private string getPropValueStr(Shape vs, string prop)
{
string value = "";
if (vs.get_CellExists("Prop." + prop, 0) != 0)
{
value = vs.get_Cells("Prop." +
prop).get_ResultStr(Microsoft.Office.Interop.Visio.VisUnitCodes.visUnitsString);
if (value == "0,0000") value = "";
}
return value;
}

private void button1_Click(object sender, EventArgs e)
{
fill();
}

private void button2_Click(object sender, EventArgs e)
{
Thread newT = new Thread(new ThreadStart(fill));
newT.Start();
}

private void fill()
{
if ((wsShape != null))
if ((wsShape.Type ==
(short)Microsoft.Office.Interop.Visio.VisShapeTypes.visTypeGroup))
for (int i = 1; i <= wsShape.Shapes.Count; i++)
wsShape.Shapes[i].get_Cells("FillForegnd").FormulaU
= "RGB(255,0,0)";
else
wsShape.get_Cells("FillForegnd").FormulaU =
"RGB(255,0,0)";
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top