wrong use of ActivityDesigner makes app really slow

I have written the designer shown below for my custom activity.

When I assign this designer as an IRootDesigner to an activity, then everything is fine.

However, if I assign this designer as an IDesigner to an activity, then my complete application becomes really slow. Menus open very slow and screen gets not refreshed as it should.

Is there something wrong with the code shown below, with respect to usage as an IDesigner?

publicclassPanedActivityDesigner : System.Workflow.ComponentModel.Design.ActivityDesigner

{

privatebool isOnPath;

///<summary>

/// Is this activity on the path to a selected component

/// while simulation is running? This status is set from

/// within the WorkflowActivityDesigner.

///</summary>

publicbool IsOnPath

{

get {return isOnPath; }

set

{

isOnPath =value;

}

}

privatebool showStatus;

///<summary>

/// Returns true, if the NOT operator has been applied to

/// this designer

///</summary>

publicbool ShowStatus

{

get {return showStatus; }

set { showStatus =value; }

}

privatePaneCollection panes;

///<summary>

/// Default constructor.

///</summary>

public PanedActivityDesigner()

{

// initialize the PaneCollection

panes =newPaneCollection();

AddPanes();

}

#region Properties

///<summary>

/// A list of visual panes, that display the activities state.

///</summary>

publicPaneCollection Panes

{

get {return panes; }

set { panes =value; }

}

///<summary>

/// Adjust the size of the designer according to the inner objects.

///</summary>

publicoverrideSize Size

{

get

{

Size size =base.Size;

if (this.ParentDesigner !=null && Panes !=null)

{

Panes.Width = 100;

Panes.Height = 60;

Panes.Location =newPoint(this.Location.X + 2,

this.ShowStatus ?this.Location.Y + 2 +Images.Negation.Height :

this.Location.Y + 2);

size.Width = Panes.Width + 4;

size.Height = Panes.Height + 4;

if (this.ShowStatus)

{

size.Height +=Images.Negation.Height;

}

}

return size;

}

}

#endregion

///<summary>

/// Adds two Pane objects to a PaneCollection.

///</summary>

///<param name="panes"></param>

void AddPanes()

{

// add two panes

panes.Clear();

Pane pane1 =newPane();

pane1.BackColor =Color.FromArgb(224, 223, 227);

pane1.Font =newFont("Tahoma", 8);

pane1.ForeColor =Color.Black;

panes.Add(pane1);

Pane pane2 =newPane();

pane2.BackColor =Color.White;

pane2.Font =newFont("Tahoma", 8,FontStyle.Italic);

pane2.ForeColor =Color.Black;

panes.Add(pane2);

}

#region Event Handlers

///<summary>

/// Controls the appearance of a filter predicate in the workflow.

///</summary>

///<param name="e"></param>

protectedoverridevoid OnPaint(ActivityDesignerPaintEventArgs e)

{

if (this.ParentDesigner !=null && panes !=null)

{

// Console.WriteLine("OnPaint");

// Console.WriteLine(this.Bounds.ToString());

// add an additional pane, if this designer IsOnPath

if (isOnPath && panes.Count == 2)

{

Pane filterResultPane =newPane();

filterResultPane.BackColor =Color.FromArgb(122, 121, 153);

filterResultPane.Font =newFont("Tahoma", 8,FontStyle.Bold);

filterResultPane.ForeColor =Color.White;

Random rnd =newRandom();

filterResultPane.Text = rnd.Next(1, 85000).ToString();

panes.Add(filterResultPane);

}

if (!isOnPath && panes.Count == 3)

{

panes.RemoveAt(2);

}

// output the predicate expression string

PanedActivity activity =this.ActivityasPanedActivity;

if (activity !=null && activity.Predicates.Count > 0 &&

this.panes.Count == 2)

{

panes[0].Text = activity.Title;

if (activity.Predicates.Count > 1)

panes[1].Text = activity.Predicates.Count.ToString() +" Eintr?ge.";

else

panes[1].Text = activity.Predicates[0];

}

else

{

panes[0].Text ="Filter";

panes[1].Text ="Kriterium";

}

// draw the panes

panes.Invalidate(e.Graphics);

// draw the negation operator

int x =this.Location.X + (this.Bounds.Width / 2) -

Images.Negation.Width / 2;

if (this.ShowStatus)

{

Helpers.DrawImageUnscaled(e.Graphics,Images.Negation,

x,this.Location.Y + 1);

}

}

}

///<summary>

/// Opens the activity editor dialog.

///</summary>

///<param name="e">MouseEventArgs</param>

protectedoverridevoid OnMouseDoubleClick(MouseEventArgs e)

{

PanedActivity activity =this.ActivityasPanedActivity;

ActivityEditorDialog dialog =newActivityEditorDialog();

dialog.Title.Text =this.Panes[0].Text;

// preselect the correct entry in the ListBox

for (int i = 0; i <= dialog.Filters.Items.Count - 1; i++)

{

string s = dialog.Filters.ItemsIdea.ToString();

if (s ==this.panes[1].Text)

dialog.Filters.SetSelected(i,true);

}

dialog.ShowDialog();

if (dialog.DialogResult ==DialogResult.OK)

{

// update activity properties

if (activity !=null)

activity.Title = dialog.Title.Text;

activity.Predicates.Clear();

foreach (object oin dialog.Filters.SelectedItems)

{

activity.Predicates.Add(activity.Title +"=" + (string)o);

}

// update visual appearance

this.Panes[0].Text = activity.Title;

if (dialog.Filters.SelectedItems.Count == 1)

{

this.panes[1].Text = dialog.Filters.SelectedItems[0].ToString();

}

if (dialog.Filters.SelectedItems.Count > 1)

{

this.panes[1].Text = dialog.Filters.SelectedItems.Count.ToString() +

" Eintr?ge";

}

}

dialog.Dispose();

this.Invalidate();

}

///<summary>

/// Defines the tooltip shown, when entering the activity with the mouse.

///</summary>

///<param name="e"></param>

protectedoverridevoid OnMouseEnter(MouseEventArgs e)

{

string title =Messages.FilterActivityTitle;

string text =Messages.FilterActivityDescription;

this.ShowInfoTip(title, text);

}

///<summary>

/// Avoid other tooltips to be shown.

///</summary>

///<param name="e"></param>

protectedoverridevoid OnMouseMove(MouseEventArgs e)

{

// do nothing here to avoid the default tooltip to appear

}

///<summary>

/// Avoid other tooltips to be shown.

///</summary>

///<param name="e"></param>

protectedoverridevoid OnMouseHover(MouseEventArgs e)

{

// do nothing here to avoid the default tooltip to appear

}

#endregion

}

[48476 byte] By [mario.muja] at [2007-12-24]
# 1

Hi.

maybe ,you would create two Designer both are assigned to the Activity.

one for IRootDesigner, one for IDesigner.

in RootDesigner , Render all detail. in Designer,just Render summary info or can be shrinked and expanded.

Matt

MattLin at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 2

Hi Matt,

thanks for your help. I have now found the cause of the problem: it was the Invalidate call in the OnPaint event. This caused recursive invalidates and flooded my system with paint events.

Regards,

mario.muja at 2007-8-31 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified