12,943,299 members (62,473 online)
Rate this:
See more: , +
Hi Everyone....

i have two listViews,named listViewEven and listViewSquare, where listViewEven adds even number by looping and listViewSquare adds square of every items of listViewEven ,
means square of every items of listViewEven should be added to listViewSquare .

and i want to run two methods concurrently.

```void even()
{
for (int i = 10; i < 20; i++)
{
listViewEven.Update();
}
}
void square()
{
foreach (ListViewItem list in listViewEven.Items)
{
string no = list.Text;
int no1 = Convert.ToInt32(no) * Convert.ToInt32(no);
listViewSquare.Update();
}
}```

but how can i implement those functions ?

Is any modification is needed ?

Posted 25-Nov-12 23:26pm

Rate this:

## Solution 1

You can't since square() depends on the result of even().
So you will have to merge them into one method with one loop. Inside that loop, do the 'even' stuff first and then the 'square' part.

```// Method names should start with a capital letter and begin with a verb
void ProcessEvenAndSquare()
{
for (int i = 10; i < 20; i++)
{

int square = i * i;
}
}```

[/Edit]
v2
krushna chandra jena 26-Nov-12 6:06am

ok..i understand but in my problem one listview is depend upon another listview. that's why i have written that types of function .
lukeer 26-Nov-12 7:40am

I thought I had been clear about what to do. But I improved my solution with a sample in code.
krushna chandra jena 26-Nov-12 8:38am

thanks for your suggestion but i want to use different loop . because i have two threads . by first thread one listview will add items(even no.) and by second thread another listview will add items(square of those even no.). and i want to run these two process parallely . What i have to do ?
lukeer 26-Nov-12 8:47am

You can't.

That's what I told you in the first two words of this solution.
Maybe "can't" is a bit too harsh, but there is no practical use for that, since the second method depends on the first one. This leads to so much synchronisation overhead between the two potential threads that you're better off sinlge-threaded.

Adding to that, you're using the main thread (a.k.a. GUI thread) in between. That will slow things down even further.

Top Experts
Last 24hrsThis month
 Maciej Los 230 CHill60 170 OriginalGriff 143 ppolymorphe 140 RyanDev 85
 OriginalGriff 4,643 CHill60 2,930 Maciej Los 2,328 Jochen Arndt 1,900 ppolymorphe 1,765