|
The reason for spending time in theses forums, I'm going to have to devote some time to linq, I use FirstOrDefault all the time
Use something that works, never look past it for other alternatives
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I just did some tests and the results were a tad surprising. The Where().FirstOrDefault() was faster than just FirstOrDefault. Find was slightly faster than that, however not using Linq or dynamic expressions at all was significantly faster than all of these methods. Something I come across quite a lot is the mistaken belief that Linq is a "fast" technology; it's actually quite slow but it's power makes it convenient and easy to use. If speed is paramount to you then avoid linq altogether.
|
|
|
|
|
I don't doubt your results in timing, but, of course, you don't share your methodology/code; as I'm sure you know, accurate timing (if such a thing is more than a myth) requires pre-jitting the code, use of a high-resolution timer, etc.
If you follow the three links I posted in my reply to the OP here, you'll see a variety of opinions regarding Where.FirstOrDefault vs. FirstOrDefault.
I wonder if the latest version of the .NET FrameWork might have slightly changed something with Where.FirstOrDefault, but, I'm too busy fixing the leaky plumbing in my code to plumb the depths of .NET source, and I don't speak IL
cheers, Bill
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
|
|
|
|
|
Your reply did remind me that my results weren't particularly relevant as I was running them in debug mode d'oh. In release mode the linq versions were much quicker, but the Where + FirstOrDefault was still quicker than the FirstOrDefault alone. The Find was also much quicker and still faster than the linq methods, but interestingly the native code benefitted very little from release mode optimisation. It was still quicker than linq but now slower than Find. Interesting indeed.
|
|
|
|
|
interesting results; thanks for posting !
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
|
|
|
|
|
Message Removed
modified 18-Dec-15 10:25am.
|
|
|
|
|
hi,all:
This question has been bothering me for a long time.
I have some series in chart1, for exampe,i have 100 series, each series have 1 point(or more). And i need paint a rectangle when mouse move, so i have code as follows, but when i run it, the rectangle can not move it smoothly, it is so slow . And i found if series number is less than 10, it maybe move fast.
how can i solve it,i have no idea.
public Form1()
{
InitializeComponent();
Series series1;
for (int i = 0; i < 100; i++)
{
series1 = new Series();
series1.Points.Add(new DataPoint(i, i)); //Just for example
series1.IsVisibleInLegend = false;
chart1.Series.Add(series1);
}
}
bool _isdown = false;
Rectangle r=new Rectangle();
private void chart1_MouseDown(object sender, MouseEventArgs e)
{
_isdown = true;
}
private void chart1_MouseMove(object sender, MouseEventArgs e)
{
if (_isdown)
{
r.Width = 100;
r.X = e.X;
r.Y = e.Y;
r.Height = 100;
panel1.Invalidate();
}
}
private void chart1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.LightBlue);
p.Width = 2;
p.Color = Color.Red;
g.DrawRectangle(p, r);
}
|
|
|
|
|
First, your code leaks resources at an insane rate. Every time the Paint event is called you're creating a new Pen and not Disposing it. This will eventually cause Windows to crash.
Create the Pen once, outside the event handler and reuse it. Dispose it when your application closes.
Next, this runs slow because you're drawing 100 series on a chart! It wasn't really designed to do that and isn't optimized to handle that kind of a load.
Every time you move the mouse with the button down, the chart has to be redrawn to "unpaint" the rectangle that your painting and redraw the rectangle in its new position and dimensions. To make it worse, you only have one data point per series! The more points you add to search series the exponentially slower the painting will become.
The only solution you have is to not draw so many chart series.
|
|
|
|
|
actually ,i need plot 20 series with 400 points, but when i plot them in the chartarea, it's also slow when mouse move.
But if i put 20*400 points in one series, the mouse move is fast. But my requirement is 20 line-series, so i don't want one series's end point line to the other's begin point.
|
|
|
|
|
The only way to speed things up is to reduce the number of points you have to draw in the graph. 20 * 400 = 8000 points.
Now, the question is why are you drawing boxes on the chart?
|
|
|
|
|
oh,i need to meet ZoomIn function. When user is doing ZoomIn, he can see his mouse's trace through a various width and heigh rectangle when mouse is down.
|
|
|
|
|
When i plot in the chart, i found chart speed is slower than other soft. Now i think chartarea refresh is cost most of time, but some times i don't need to refresh background series, just need to use invalidate to call paint function.
So is there any method to stop backgound series refresh ,not refresh paint function content?
|
|
|
|
|
No, there isn't, and YES, you HAVE TO PAINT THE BACKGROUND, which means painting the entire chart area. It's the only way to "undo" the previous painting of your rectangle so it can be repainted with it's new coordinates and size.
|
|
|
|
|
oh, but why some other soft can work so fast? Maybe other language can good work for this?
|
|
|
|
|
The language used doesn't matter at all. What does matter is the design of your graphing component, which you didn't write. You're trying to adapt a graphing component that isn't designed to do the job you want to do.
If you make your own graphing component that also supports drawing boxes on it and is OPTIMIZED to support what you want to do, then you can get the speed out of it.
|
|
|
|
|
|
i want is that, when i fetch data from database then labels dynamically added to my form.
i have a code but this show only one data, i want total result of query generate automatically label and set data into label.
my code is .
`
con.Open();
DataTable table = new DataTable();
string sqlText = "SELECT DATEDIFF(DAY, [meas_duedate], GETDATE()) , meas_id, client_id FROM tlb_meas_master"
SqlCommand cmd = new SqlCommand(sqlText, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
}
lbl_date.Text = dr.GetValue(0).ToString();
lbl_mea_id.Text = dr.GetValue(1).ToString();
lbl_cli_id.Text = dr.GetValue(2).ToString();
}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n" + ex.Message);
con.Close();
}
`please help me....
|
|
|
|
|
You already posted this in the QA section. Don't post the same question multiple times.
|
|
|
|
|
With above code it will only show you last record value as you iterate records with data reader object
modified 20-Sep-20 21:01pm.
|
|
|
|
|
Hello All,
i have command - Get-WmiObject -Query "select * from win32_printer" -ComputerName ""
I would like to use Textbox with c# instead type computer type manually. How can i accomplish it?
Thanks.
|
|
|
|
|
|
we have ecomerance site. we are trying to flipkart seller api. to display our products in flipkart.
i am unable get start with work. not getting idea how to call REST API with OAuth.
from flipkart site it is showing to call.
oauth/token?grant_type=client_credentials&scope=Seller_Api,Default
not having idea how to call from c#.Net
Please any guide or help how call rest api with oAuth in c#.Net
Thanks,
Raja Ramesh
raja
|
|
|
|
|
What is wrong with this code that is not updating my datagrid and consequentetly the data base table? Thank you for any help.
using (OdbcConnection connection = CreateConnection())
{
string CmdText = "update lojas set Bloqueado =@bloqueador, DataFim = @DataFim, Nome = @Nome where Id =@Id";
OdbcCommand cm = new OdbcCommand(CmdText, connection);
cm.CommandType = CommandType.Text;
connection.Open();
cm.Parameters.AddWithValue("@Id", grid_lic.CurrentRow.Cells[0].Value);
cm.Parameters.AddWithValue("@bloqueador",grid_lic.CurrentRow.Cells[3].Value);
cm.Parameters.AddWithValue("@DataFim",grid_lic.CurrentRow.Cells[4].Value);
cm.Parameters.AddWithValue("@Nome",grid_lic.CurrentRow.Cells[6].Value);
cm.ExecuteNonQuery();
|
|
|
|
|
There is no code here to update the datagrid. You would need to refresh it after the database has been updated. E.g. set the datasource to null and then rebind it or use a BindingSource.
If the database is not being updated by this query then debug it to ensure the value for Id matches what you have in your data
|
|
|
|
|
When I change the data in the cells of the DataGridView, and I debug, the values that are shown are the new ones, but at the end the DataGridView is not updated. Can you please give an example of possible code to complete what I already have? Thanks.
|
|
|
|