Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic 100% cpu (Read 3032 times)
Milo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 29
Joined: Jul 16th, 2007
100% cpu
Oct 27th, 2007 at 8:18am
Print Post  
I'm using the calendar on week view. All is well until I add ann appointment, it adds it fine, and renders great. However the CPU utilisation goes to 100% and stays there... his the init on the control..

[code]
this._calendar.AllowInplaceCreate = false;
this._calendar.AllowInplaceEdit = false;
this._calendar.CurrentView = MindFusion.Scheduling.WinForms.CalendarView.WeekRange;
this._calendar.Date = new System.DateTime(2007, 7, 22, 0, 0, 0, 0);
this._calendar.DateTimeFormat = ((System.Globalization.DateTimeFormatInfo)(resources.GetObject("_calendar.DateTimeFormat")));
this._calendar.EndDate = new System.DateTime(2007, 8, 29, 0, 0, 0, 0);
this._calendar.ItemSettings.HeaderSize = 20;
this._calendar.ItemSettings.MoveBandSize = 5;
this._calendar.ItemSettings.Padding = 0;
this._calendar.ItemSettings.ResizeBandSize = 5;
this._calendar.ItemSettings.ShowClocks = MindFusion.Scheduling.WinForms.ShowClocks.Never;
this._calendar.ItemSettings.Size = 60;
this._calendar.ItemSettings.Spacing = 0;
this._calendar.ItemSettings.UseStyledText = MindFusion.Scheduling.WinForms.State.Disabled;
this._calendar.Location = new System.Drawing.Point(6, 32);
this._calendar.MonthSettings.DayOfWeekFormat = MindFusion.Scheduling.WinForms.DayOfWeekFormat.Full;
this._calendar.Name = "_calendar";
this._calendar.Size = new System.Drawing.Size(454, 450);
this._calendar.TabIndex = 5;
this._calendar.Theme = MindFusion.Scheduling.WinForms.ThemeType.Windows2003;
this._calendar.WeekRangeSettings.DayNamesHeaderHeight = 24;
this._calendar.WeekRangeSettings.DayOfWeekFormat = MindFusion.Scheduling.WinForms.DayOfWeekFormat.Full;
this._calendar.WeekRangeSettings.DaySettings.HeaderSize = 20;
this._calendar.WeekRangeSettings.GroupWeekends = MindFusion.Scheduling.WinForms.State.Disabled;
this._calendar.WeekRangeSettings.VisibleRows = 8;
this._calendar.ItemModifying += new MindFusion.Scheduling.WinForms.ItemModifyConfirmEventHandler(this._schedule_itemModifying);
this._calendar.ItemClick += new MindFusion.Scheduling.WinForms.ItemMouseEventHandler(this._calendar_itemClick);
this._calendar.DateClick += new MindFusion.Scheduling.WinForms.ResourceDateEventHandler(this._calendar_dateclick);
this._calendar.VScroll += new System.Windows.Forms.ScrollEventHandler(this._calendar_VScroll);
[/code]

I've put break points in all my events and their not being hit...

Any ideas?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: 100% cpu
Reply #1 - Oct 27th, 2007 at 9:26am
Print Post  
I have created a few appointments in week view in the Demo example, and the CPU stays at 0% on my system. Have you seen 100% CPU usage when running the project in debug mode (F5) or when starting it without debugging (Ctrl+F5)? I believe the debugger runs a thread that might add to the CPU usage, so check how it works when debugging is disabled.

Creating new items might also start the garbage collector, which increases the CPU usage for a few seconds.

If you are using reminders, Planner.NET will run a timer that periodically checks if a reminder event should be raised. However, that should not decrease the performance much, especially if there is just one item in the schedule.

Stoyan
  
Back to top
 
IP Logged
 
Milo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 29
Joined: Jul 16th, 2007
Re: 100% cpu
Reply #2 - Oct 28th, 2007 at 4:41pm
Print Post  
Thanks for that, I've done some more research on this. I have a custom Appointment class which is working well. I have a custom property for the appointment type, AM PM and Full day which is a enum.

I'm overriding the brush colours on the schedule type e.g.

[code]        public override Style Style
       {
           get
           {
               if (this.booked)
               {
                   base.Style.Brush = new MindFusion.Drawing.SolidBrush(System.Drawing.Color.Yellow);
                   base.Style.HeaderBrush = new MindFusion.Drawing.SolidBrush(System.Drawing.Color.Yellow);
                   base.Style.HeaderTextColor = System.Drawing.Color.Black;
               }
               else
               {
                   base.Style.Brush = new MindFusion.Drawing.SolidBrush(MyApp.getBgColor(this.SchType));
                   base.Style.HeaderBrush = new MindFusion.Drawing.SolidBrush(MyApp.getBgColor(this.SchType));
                   base.Style.HeaderTextColor = MyApp.getColor(this.SchType);
               }
               return base.Style;
           }
           set
           {
               base.Style = value;
           }
       }[/code]

When I run this, the proc goes to 100% and stays there, also if I write some debug output. The property is referenced, when adding an appointment, and ongoing even when the control is at idle. Once every second and more if I mouse over the control.

Any ideas?

  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: 100% cpu
Reply #3 - Oct 29th, 2007 at 5:16am
Print Post  
The Style property of the items is accessed very often (especially when the item is being redrawn). Creating new brushes and assigning them to the base class' style every time the property is accessed is a very expensive operation. Even more, changing a property of the base class' style causes an automatic redrawing request (because the item's appearance is actually being modified). The redrawing request causes the item to be drawn again and this is the reason for the 100% CPU usage. To avoid this, perform the modification of the base class' style  in a different place. The following code gives you an idea how to do it:

Code
Select All
public class MyItem : Appointment
{
	public MyItem()
	{
		// Initialize booked flag and the brushes of the base style accordingly
		Booked = false;
	}

	public bool Booked
	{
		get { return booked; }
		set
		{
			booked = value;

			if (booked)
			{
				base.Style.Brush = new MindFusion.Drawing.SolidBrush(System.Drawing.Color.Yellow);
				base.Style.HeaderBrush = new MindFusion.Drawing.SolidBrush(System.Drawing.Color.Yellow);
				base.Style.HeaderTextColor = System.Drawing.Color.Black;
			}
			else
			{
				base.Style.Brush = new MindFusion.Drawing.SolidBrush(Color.Red);
				base.Style.HeaderBrush = new MindFusion.Drawing.SolidBrush(Color.Red);
				base.Style.HeaderTextColor = Color.White;
			}
		}
	}

	private bool booked = false;
}
 


You don't even have to override the base class' Style property. The brushes and colors are modified only when the booked field is changed.

Meppy
  
Back to top
 
IP Logged
 
Milo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 29
Joined: Jul 16th, 2007
Re: 100% cpu
Reply #4 - Oct 29th, 2007 at 6:16am
Print Post  
Now you explained it, it seems obvious now.  Embarrassed

Thank Meppy, and it works a treat.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint