Time to draw 2 usercontrols on a form is depend on each other.
-
Hi all. I have a problem. really need some help. I have a form contains 2 usercontrols name: usercontrol 1 and usercontrol 2. I use System.Timers.Timer.Elapsed to redraw usercontrol 1 and usercontrol 2 follow interval(interval of usercontrol 1 = 100ms. interval of usercontrol 2 = 1000ms). I measure time to draw usercontrol 1 and usercontrol 2 and I realize that time to draw usercontrol 1 is increase when usercontrol 2 has been drawing, when usercontrol 2 complete, time to draw usercontrol 1 is decrease. Is there anyway to solve it(time to draw usercontrol 1 is stable, it's not depend on the drawing usercontrol 2).
-
Hi all. I have a problem. really need some help. I have a form contains 2 usercontrols name: usercontrol 1 and usercontrol 2. I use System.Timers.Timer.Elapsed to redraw usercontrol 1 and usercontrol 2 follow interval(interval of usercontrol 1 = 100ms. interval of usercontrol 2 = 1000ms). I measure time to draw usercontrol 1 and usercontrol 2 and I realize that time to draw usercontrol 1 is increase when usercontrol 2 has been drawing, when usercontrol 2 complete, time to draw usercontrol 1 is decrease. Is there anyway to solve it(time to draw usercontrol 1 is stable, it's not depend on the drawing usercontrol 2).
Why are you using a timer to re-draw ? Is this a game ? Normally, if there's custom drawing being done in a UserControl (or other container), this is done by using the 'Paint event. Please tell us what your goal is here. Is there any dependency (like accessing the same Database) between the two UserControls ? Are both of the UserControls instances of the same UserControl Object, or do they both inherit from a common Class or Interface ?
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
-
Why are you using a timer to re-draw ? Is this a game ? Normally, if there's custom drawing being done in a UserControl (or other container), this is done by using the 'Paint event. Please tell us what your goal is here. Is there any dependency (like accessing the same Database) between the two UserControls ? Are both of the UserControls instances of the same UserControl Object, or do they both inherit from a common Class or Interface ?
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
-
I create a usercontrol name: panel1, use timer.Elapsed += OnTimerTick; OnTimerTick will call draw a function. I add 2 panel1 name: panel11 and panel12 into a form. usercontrol 1 draw into panel11, usercontrol 2 draw into panel12.
Hi, You still haven't answered the question about why you are using Timers to control painting/drawing, and what it is your painting/drawing. Please be specific.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
-
Hi, You still haven't answered the question about why you are using Timers to control painting/drawing, and what it is your painting/drawing. Please be specific.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
-
I want to redraw usercontrol 1 and usercontrol 2 follow cycle(usercontrol 1 and usercontrol 2 always redraw follow Timer.Interval of each control), so I use Timer.Elapsed event to do that. It draws line, text, ... Sorry for bad English.
Perhaps if you could show us a cut down version of the paint code for both controls.
-
Perhaps if you could show us a cut down version of the paint code for both controls.
usercontrol 1 will invoke 2 functions, one of it:
public void DrawControl(Graphics g)
{
int X = 599;
int Y = 10;
int Width = 225;
using (GraphicsPath path = GraphicsHelper.Create(X, Y, 224, 119, 5))
{
using (Pen frameWithBlackBgrd = new Pen(CWColors.FrameWithBlackBgrd))
{
g.DrawPath(frameWithBlackBgrd, path);
}
}if (GuiResInfoMng.Instance.Lang != null && GuiResInfoMng.Instance.Param != null) { using (SolidBrush fixedTextWithBlackBgrd = new SolidBrush(CWColors.FixedTextWithBlackBgrd)) { g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS\_COM\_TOTALCNT), FontFactory.Instance.GetFont(LangId.FNT\_M2), fixedTextWithBlackBgrd, X, Y); g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS\_COM\_PASS), FontFactory.Instance.GetFont(LangId.FNT\_M2), fixedTextWithBlackBgrd, X, Y + 23); g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS\_COM\_NG), FontFactory.Instance.GetFont(LangId.FNT\_M2), fixedTextWithBlackBgrd, X - 1, Y + 46); } } using (SolidBrush variableText = new SolidBrush(CWColors.VariableText)) { g.DrawString(ParamHelper.GetParamStr(ParamId.TOTALCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT\_M2), variableText, X + Width - 60, Y); g.DrawString(ParamHelper.GetParamStr(ParamId.PASSCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT\_M2), variableText, X + Width - 60, Y + 23); g.DrawString(ParamHelper.GetParamStr(ParamId.NGCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT\_M2), variableText, X + Width - 60, Y + 46); } }
-
usercontrol 1 will invoke 2 functions, one of it:
public void DrawControl(Graphics g)
{
int X = 599;
int Y = 10;
int Width = 225;
using (GraphicsPath path = GraphicsHelper.Create(X, Y, 224, 119, 5))
{
using (Pen frameWithBlackBgrd = new Pen(CWColors.FrameWithBlackBgrd))
{
g.DrawPath(frameWithBlackBgrd, path);
}
}if (GuiResInfoMng.Instance.Lang != null && GuiResInfoMng.Instance.Param != null) { using (SolidBrush fixedTextWithBlackBgrd = new SolidBrush(CWColors.FixedTextWithBlackBgrd)) { g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS\_COM\_TOTALCNT), FontFactory.Instance.GetFont(LangId.FNT\_M2), fixedTextWithBlackBgrd, X, Y); g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS\_COM\_PASS), FontFactory.Instance.GetFont(LangId.FNT\_M2), fixedTextWithBlackBgrd, X, Y + 23); g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS\_COM\_NG), FontFactory.Instance.GetFont(LangId.FNT\_M2), fixedTextWithBlackBgrd, X - 1, Y + 46); } } using (SolidBrush variableText = new SolidBrush(CWColors.VariableText)) { g.DrawString(ParamHelper.GetParamStr(ParamId.TOTALCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT\_M2), variableText, X + Width - 60, Y); g.DrawString(ParamHelper.GetParamStr(ParamId.PASSCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT\_M2), variableText, X + Width - 60, Y + 23); g.DrawString(ParamHelper.GetParamStr(ParamId.NGCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT\_M2), variableText, X + Width - 60, Y + 46); } }
That's the paint routine for one control, not two.
-
That's the paint routine for one control, not two.
usercontrol 2 will invoke draw function:
public void DrawGraph(Graphics g)
{
g.SmoothingMode = SmoothingMode.HighSpeed;
//Draw background
_frameXBar.DrawBackground(g, XbarPos);
_frameNumber.DrawBackground(g, NumberPos);
_frameRS.DrawBackground(g, RsPos);//Draw XBar DrawXBarBase(g); DrawXbarGraph(g); ////Draw RS DrawRSBase(g); DrawRSGraph(g); ////Draw Number DrawNumber(g); }
DrawGraph function will call some function: Ex:
private void DrawRSGraph(Graphics g)
{
if (IsAllLine)
{
if (IsR)
{
if (IsFullLine)
{
DrawPolyline(_dataAllLineRFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
else
{
DrawPolyline(_dataAllLineRPassNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
}
else
{
if (IsFullLine)
{
DrawPolyline(_dataAllLineSFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
else
{
DrawPolyline(_dataAllLineSPassNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
}
}
else
{
if (IsR)
{
if (IsFullLine)
{
DrawPolyline(_dataForLineRFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
else
{
DrawPolyline(_dataForLineRPassNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
}
else
{
if (IsFullLine)
{
DrawPolyline(_dataForLineSFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
else
{
DrawPolyline(_dataForLineSPassNumber, g, _ -
usercontrol 2 will invoke draw function:
public void DrawGraph(Graphics g)
{
g.SmoothingMode = SmoothingMode.HighSpeed;
//Draw background
_frameXBar.DrawBackground(g, XbarPos);
_frameNumber.DrawBackground(g, NumberPos);
_frameRS.DrawBackground(g, RsPos);//Draw XBar DrawXBarBase(g); DrawXbarGraph(g); ////Draw RS DrawRSBase(g); DrawRSGraph(g); ////Draw Number DrawNumber(g); }
DrawGraph function will call some function: Ex:
private void DrawRSGraph(Graphics g)
{
if (IsAllLine)
{
if (IsR)
{
if (IsFullLine)
{
DrawPolyline(_dataAllLineRFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
else
{
DrawPolyline(_dataAllLineRPassNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
}
else
{
if (IsFullLine)
{
DrawPolyline(_dataAllLineSFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
else
{
DrawPolyline(_dataAllLineSPassNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
}
}
else
{
if (IsR)
{
if (IsFullLine)
{
DrawPolyline(_dataForLineRFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
else
{
DrawPolyline(_dataForLineRPassNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
}
else
{
if (IsFullLine)
{
DrawPolyline(_dataForLineSFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
else
{
DrawPolyline(_dataForLineSPassNumber, g, _Hi, I'd like to suggest you now go back to your original question here and edit it so it includes the information/code you've shared. cheers, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
-
Hi all. I have a problem. really need some help. I have a form contains 2 usercontrols name: usercontrol 1 and usercontrol 2. I use System.Timers.Timer.Elapsed to redraw usercontrol 1 and usercontrol 2 follow interval(interval of usercontrol 1 = 100ms. interval of usercontrol 2 = 1000ms). I measure time to draw usercontrol 1 and usercontrol 2 and I realize that time to draw usercontrol 1 is increase when usercontrol 2 has been drawing, when usercontrol 2 complete, time to draw usercontrol 1 is decrease. Is there anyway to solve it(time to draw usercontrol 1 is stable, it's not depend on the drawing usercontrol 2).
How many "cores" does your CPU have? Getting the most out of multi-threading (usually) requires multiple cores. You want control 1 to be "stable" ... What about control 2? If control 1 can be stable at the expense of control 2, then you could implement a "priority" system where control 1 is allowed to preempt control 2 (for drawing), but control 2 is not allowed to preempt control 1. There are various ways of blocking and testing for locks to accomplish this. Be aware that "drawing" has always been a fairly slow operation relative to compute time (that's why it is not wise to update a "progress bar" too frequently when it comes to critical operations). Also, 100ms is (usually) the limit at which a user can detect "lag" in a UI; you might consider raising the interval for control 1 to 200ms and checking the results. And, since the interval of control 2 is a multiple of control 1, you might consider using a single timer, and "dispatching" control 2 once for every n times control 1 is dispatched; i.e. dispatch either control 1 or 2, but not so that both are running at the same time (when redrawing).
-
How many "cores" does your CPU have? Getting the most out of multi-threading (usually) requires multiple cores. You want control 1 to be "stable" ... What about control 2? If control 1 can be stable at the expense of control 2, then you could implement a "priority" system where control 1 is allowed to preempt control 2 (for drawing), but control 2 is not allowed to preempt control 1. There are various ways of blocking and testing for locks to accomplish this. Be aware that "drawing" has always been a fairly slow operation relative to compute time (that's why it is not wise to update a "progress bar" too frequently when it comes to critical operations). Also, 100ms is (usually) the limit at which a user can detect "lag" in a UI; you might consider raising the interval for control 1 to 200ms and checking the results. And, since the interval of control 2 is a multiple of control 1, you might consider using a single timer, and "dispatching" control 2 once for every n times control 1 is dispatched; i.e. dispatch either control 1 or 2, but not so that both are running at the same time (when redrawing).
Thank for your reply. My cpu has 2 core. The first I want control 1 to be stable, control 2 still not care. I measure time to draw control 1, AVG value = 15ms-> 20 ms, usually it ~ 10 ms, however when control 2 has been drawing, time to draw control 1 increase up to ~ 200ms. When control 2 complete it decrease down to ~ 10ms.(I want to both control are running at the same time, the drawing of controls is independence)
-
Thank for your reply. My cpu has 2 core. The first I want control 1 to be stable, control 2 still not care. I measure time to draw control 1, AVG value = 15ms-> 20 ms, usually it ~ 10 ms, however when control 2 has been drawing, time to draw control 1 increase up to ~ 200ms. When control 2 complete it decrease down to ~ 10ms.(I want to both control are running at the same time, the drawing of controls is independence)
-
Your measurements seem to indicate that the controls cannot run at the same time if you expect control 1 to always draw at under 100ms without considering what control 2 is doing (or vice versa).