|
I'm sorry, but your code really confuses me. Why are you doing i++ in the body of your for loops? Which part do you think is really causing the issue because the way you are creating your listview here is going to be really slow.
|
|
|
|
|
Why the heck are you putting 100,000 items into a list view?
Do you hate your users?
Or did you not think "What would this be like to use?" as well as "why is this slow?"
Don't. No user on this planet is going to sit there and look through 100,000 rows of information - they need it abstracted, sorted, searchable, filterable, just to bring the volume down to a meaningful level.
Use a List or a DataTable, and do a bulk insert into SQL, or do each row as you create it (though that is slower) - but don't try to put it into anything like a display control!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Thanks a lot for your suggestion,
But there are some calculations to be done. is it a good idea and best way to use the same in Database - Store procedure?
And also, 100,000 rows will not be in UI, rather will do some calculation to get the summery to update on the database.
|
|
|
|
|
If they aren't in the UI, then why would you waste time and resources putting them into a UI control, which has to do a fair amount of processing every time you add an element?
Let's go back a stage: you have 100,000 items of information. Where do they come from? What are you doing with them? How many results do you get from these items? How much of this are you inserting into the DB?
Because it may be that you are going completely the wrong way!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Wrong tool for the job (as OG said) and probably the wrong place as well. If you MUST do this in the client app (winforms) then use a collection or datatable (if you are inserting 100k records then use bulk insert from a datatable) to hold the data not a UI control.
If you are looking up the loan details from the database then consider inserting the emp details without the loan info and do an update in the database, this will take advantage of the grunt a database brings to processing volume records.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks
What about Store Procedure to achieve this process?
|
|
|
|
|
I would put all the data into a datatable via your loop, insert that into a staging table using bulkcopy. Then craft a stored proc that implements the loan function on each record as it is inserted into your final destination table either as a single record or a set depending on your function.
You still have not mentioned the database you are using.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The database is MS SQL (2008)
|
|
|
|
|
That's just details of implementation.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
A stored procedure is a bit moot, your primary issue is the number of database calls that you're making. Drop it to one call and you should see a dramatic increase in performance.
Some of the more reasonable solutions I've seen revolve around using SqlBulkCopy[^]
|
|
|
|
|
Either you bulk load or you make sure to not recreate the connection each time in the loop.
I often user StringBuilder concatenation and send 1000 insert queries in one go...
so you would have something like:
StringBuilder builder = new StringBuilder("");
for(int i = 0; i < someLength;i++){
builder.append(the insert query + ";");
if(i%1000 == 0){
ExecuteQuery(builder.ToString());
builder = new StringBuilder("");
}
}
Hope this gives you an idea.
|
|
|
|
|
I am using the following code
Uri collectionUri = new Uri(@"http://XXX.XXX.XXX.XXX:8080/tfs/projectcollection");
TfsTeamProjectCollection teamProjectCollection =
new TfsTeamProjectCollection(collectionUri, new NetworkCredential(@"user","userpassword"));
teamProjectCollection.EnsureAuthenticated();
WorkItemStore workItemStore = teamProjectCollection.GetService<WorkItemStore>();
string wiql = "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] FROM WorkItems " +
"WHERE [System.TeamProject] = 'Pathway' " + "AND [System.State] = 'System Test Complete' " +
"AND [Sagitec.Common.TestPhase] = '4.B – System Testing' ORDER BY [System.Id]";
WorkItemCollection workItemCollection = workItemStore.Query( wiql);
foreach (WorkItem wi in workItemCollection)
{
wi.Fields["Assigned To"].Value = "Srikanth";
wi.Fields["State"].Value = "Ready for Client Review";
wi.Fields["Reason"].Value = "Ready for Client Review";
MessageBox.Show(wi.Fields["Assigned To"].Value + " + " + wi.Fields["State"].Value + " + " + wi.Fields["Reason"].Value);
}
Now, when i see the values of respective Fields in workitem object, they are not holding the values that I have set. Instead they have value which is already there in the workitem. I checked about ByPassRules. But I dont see the enum WorkItemStoreFlags in my namespace. Can you please help me in setting the values for fields values in my workitem?
|
|
|
|
|
Is there a way to initiate a connection from the server to a specific client? The only examples I have been able to find use the TCPListener to accept all clients that try to connect.
|
|
|
|
|
Yes, by opening a client-socket on the server and connecting to a listener on the client. Effectively, that turns the server into the client, and the client into the server.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Makes sense. I'll give it a try.
|
|
|
|
|
kruegs35 wrote: Is there a way to initiate a connection from the server to a specific client? Sort of. The client needs to be listening. You can't initiate a connection to any device on your own for security reasons. The "client" needs to be listening.
I wrote an app years ago for IM and had the client and server both open 2 ports. The server sent on the same port the client listened to and the client sent on the same port the server listened to.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Although answered else it should be noted that normally this is a pointless exercise.
The point of a server is to act on behalf of the client. A client can initiate requests and respond to requests from the server on the same socket. And server are more likely to be accessible than clients. For a server to connect to a client the client must be visible on the network. And as is often the case since the network is actually the internet most clients will not be accessible. And even in intranets network security will often limit incoming connection requests to client machines.
There might be a message based reason for this (like the way FTP can work) but if so it is still going to be better to some degree to have the client initiate another socket to the server rather than the reverse.
|
|
|
|
|
Hey guys, I have a strange problem. I am trying to write a function that looks at a TextBox that, if it is equal to a certain value, changes the value of a string to something else.
Here is my code:
I define the string in Main:
string strDoorsOption1 = "test";
The Method is defined as:
public void optionCheck(TextBox txt, string str)
{
if (txt.Text == "0")
{
str = "+++";
}
else
{
str = "---";
}
}
I call the Method like this:
private void chkDoorsSafetyLaminated_CheckedChanged(object sender, EventArgs e)
{
checkBoxClick3(chkDoorsSafetyLaminated, txtDoorsSafety1);
optionCheck(txtDoorsSafety1, strDoorsOption1);
}
checkBoxClick3 is another Method that works as intended to change the value of a TextBox.
For reference, it is defined as follows:
public void checkBoxClick3(CheckBox check, TextBox txt)
{
if (check.CheckState == CheckState.Checked)
{
txt.Text = "1";
}
else
{
txt.Text = "0";
}
}
This works...:
if (txtDoorsSafety1.Text == "0")
{
strDoorsOption1 = "+++";
}
else
{
strDoorsOption1 = "---";
}
But when I call optionCheck(txtDoorsSafety1, strDoorsOption1); it acts as if the method is empty. It completely compiles with no errors or warnings, it simply does nothing.
Any help would be appreciated.
|
|
|
|
|
Aight, let's call it, using your constant and the textbox.
public void optionCheck(TextBox txt, string str)
{
if (txt.Text == "0")
{
str = "+++";
}
else
{
str = "---";
}
}
optionCheck(textBox1, "test");
if (textBox1.Text == "0")
{
}
else
{
str = "...";
} Means that "str" gets set to "---", and then goes out of scope. Did you mean to set anything else, like a textbox or a checkbox?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Actually, I was able to finally figure this out, I was missing a `ref` in the Method Definition:
public void optionCheck(TextBox txt, ref string str)
Then when I call it:
optionCheck(txtDoorsSafety1, ref strDoorsOption1)
That works...
Though I have to say... the concept of having to write `ref` twice seems counterintuitive to me.
|
|
|
|
|
Zachery Hysong wrote: the concept of having to write `ref` twice seems counterintuitive to me. The first time (in the method declaration) you use it to explain to the compiler that you're passing the string by reference, not as a value.
The second could be omitted if the language would allow it; it doesn't because it helps to determine what is being passed. If you read the call to the method, then without the additional "ref" keyword it'd be impossible to say whether it is passed as a value or a reference without looking up the method-signature.
It also prevents mistakes; you can never pass in a value by "mistake"
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Look at the code:
public void optionCheck(TextBox txt, string str)
That means that both txt and str are Value parameters - the default - which means that the value of the variable is copied and the copy passed to the method when it is called - so any changes to the value of the variable affect the copy, and not the original. When the method ends, the modified value is thrown away.
This is exactly the normal behaviour - and it is exactly what you want to happen!
Take an example, and think about what would happen if what you expected to happen did:
public void Change(int i)
{
i = i + 2;
} Now, that's fine when you call it like this:
int iOriginal = 6;
Change(iOriginal);
Console.WriteLine(iOriginal); You will be expecting to get "8" printed.
But...what happens if you do this:
Change(6);
Console.WriteLine(6); The last thing you want is to get "8" printed!
But that is exactly what "should" happen - you passed in a value, the method changed it and tit affected the outside world. The method doesn't know - and can't check - that you are passing in a value that can be variable!
You can do what you want, but you have to tell teh system that that is exactly what you want to happen:
public void optionCheck(TextBox txt, ref string str)
{
if (txt.Text == "0")
{
str = "+++";
}
else
{
str = "---";
}
} And call it like this:
optionCheck(txtDoorsSafety1, ref strDoorsOption1); But then you can't call it with a string constant because will get a compilation error, and the system now knows you want to change a constant, and you can't do that!
Make sense?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Yes, and this is one of the best explanations ever. Thank you.
|
|
|
|
|
You're welcome!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
You're passing the parameter by value, which means that any changes you make to the parameter within the method will be discarded when the method returns. I suspect you meant to pass it by reference, so that the changes would be copied back.
Passing Parameters (C# Programming Guide)[^]
In this case, since you're not using the value of the parameter within the method, and you're always assigning a value to it before the method returns, you should declare it as an out parameter.
public void optionCheck(TextBox txt, out string str)
{
if (txt.Text == "0")
{
str = "+++";
}
else
{
str = "---";
}
}
optionCheck(txtDoorsSafety1, out strDoorsOption1);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|