|
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.
|
|
|
|
|
usercontrol 2 will invoke draw function:
public void DrawGraph(Graphics g)
{
g.SmoothingMode = SmoothingMode.HighSpeed;
_frameXBar.DrawBackground(g, XbarPos);
_frameNumber.DrawBackground(g, NumberPos);
_frameRS.DrawBackground(g, RsPos);
DrawXBarBase(g);
DrawXbarGraph(g);
DrawRSBase(g);
DrawRSGraph(g);
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, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
}
}
}
}
|
|
|
|
|
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.
|
|
|
|
|
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)
|
|
|
|
|
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).
|
|
|
|
|
I can confirm that both control are draw at the same time.
|
|
|
|
|
|
I have a 20 records in a database table and I want to read a field in each record fieldA. For each record that fieldA contains data I want to do a count of that field. So if 10 records have data in fieldA then my count for fieldA will be 10.
Anyone know how to do this in C# ?
|
|
|
|
|
You can probably use some clever SQL to do it; try the database forum.
|
|
|
|
|
Well, assuming you are connecting to a database and want to use straightforward SQL, you could just execute the following scalar command:
SELECT COUNT(1) FROM MyTable WHERE FieldA IS NOT NULL So, you would have something like
private int GetCommand(IDbConnection dbConnection)
{
IDbCommand command = dbConnection.CreateCommand();
command.CommandText = "SELECT COUNT(1) FROM MyTable WHERE FieldA IS NOT NULL";
command.CommandType = CommandType.Text;
dbConnection.Open();
object output = command.ExecuteScalar();
dbConnection.Close();
int retValue;
int.TryParse(output, ref retValue);
return retValue;
}
|
|
|
|
|
Pete O'Hanlon wrote: int.TryParse(output, ref retValue);
That's not going to compile - TryParse expects the first parameter to be a string , not an object .
It should be safe to unbox the output variable directly to an int . Otherwise, Convert.ToInt32 should work.
Also, it would probably be a good idea to wrap the IDbCommand in a using block, and test whether or not you need to open the connection, since it might already be open.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Also, the CommandType "text" does not need to be set, it is (very conveniently) the default; since it is not a nullable enum it will always have a value, meaning a default must exist.
..but still bonuspoints, as the code is not tied to a specific IDbCommand implementation, and he's using the factory-method to create a command of the correct type
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
To be fair, I just coded this in the textblock as a minimal version. It's been a long time since I went away from the Db libraries I've built up that hide all this implementation.
|
|
|
|
|
As Richard says, this is easiest in SQL:
SELECT SUM(CASE WHEN fieldA IS NOT NULL THEN 1 ELSE 0 END) FROM MyTable
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Wouldn't just the COUNT function do this?
SELECT COUNT(fieldA) FROM MyTable
In this form it counts the NON NULL values.
See: SQL COUNT() Function[^] and COUNT (Transact-SQL)[^]
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
Yes...it would...
Sorry about that, it's been one of those weeks...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I should have said I am trying to do this using LINQ:
I have a 20 records in a database table. Each record has and ID. I want to read a field in each record fieldA. I only want to read the records that have an ID '1'. For each record that has an ID '1' and fieldA Is Not Null I want to return a count of those records.
So if 10 records have data in fieldA and have ID '1' then my count for fieldA will be 10.
Anyone know how to do this in Linq?
|
|
|
|
|
How about something like:
int count = yourDbContext.yourEntityCollection.Where(entity => entity.ID == 1 && entity.FieldA != null).Count();
You have just been Sharapova'd.
|
|
|
|
|
Or, more simply:
int count = yourDbContext.yourEntityCollection.Count(entity => entity.ID == 1 && entity.FieldA != null);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Not sure about Linq to SQL, but (for Linq to objects and XML) I have always found Where(predicate).Count() to be performing better than .Count(predicate) .
--EDIT
Here's a StackOverflow question[^] that might interest you.
You have just been Sharapova'd.
|
|
|
|
|
The optimizations only apply to in-memory LINQ queries (LINQ to Objects and LINQ to XML). With LINQ to SQL and Entity Framework, both versions should produce an identical SQL query.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Indeed, they should. But I have always used the Where(predicate).Count() version, so that came implicitly when I posted the answer.
You have just been Sharapova'd.
|
|
|
|
|
This is the code that I am looking to get a Count of complexQuery.
string refName = entity.GetAttributeValue<string>("contractorname");
var complexQuery = (from c in orgContext.CreateQuery<contractorframe>()
join e in orgContext.CreateQuery<dcc_eval>()
on c.ContractorName equals e.RegardingObjectId.ToString()
where e.RegardingObjectId.ToString() == refName
and e.QW Is Not Null)
modified 15-Oct-15 10:27am.
|
|
|
|
|