The software that I'm developing in C # using
SharpDevelop behaves in a strange way. I'll try to describe it briefly,
although I know that it will not be easy.
I have a window in which I have
three ListView. Clicking on a button through a
for loop I populate these three ListView with simple text strings coming from a
List already populated. The filling and the display is
not immediate. In fact, I want each row to
appear every few milliseconds, and for this I use System.Threading.Thread.Sleep.
Well, when I run the software
from making within the development environment, it behaves the way I want
without any problem, but when I run the software on the outside, simply by
double-clicking the executable, when I press the button to show the contents of the
ListView, a strange thing happens,… the ListView began to be populated, and the
lines began to compare on the screen according to the delay set by me, then at
a certain point the program seems like it locks... in the listview doesn't appear anything
and the only thing I see is the mouse cursor letting me know that the program
is working. In fact, the program has not
crashed, is continuing to follow the instructions and only when it arrives at
the end of the for loop becomes available again and shows the listview filled
with all the remaining strings. The problem is that, for
example, from the string 21 to 200 I have not seen any row appearing on the
screen as I wanted.
What could be the explanation for this strange behaviour? Does anyone have any idea on how to solve it?

pixel pixPosted Oct 29, 2012, 3:57 AM
// This is the function that I call when I click on the button that will populate the listview
void BtSimClick(object sender, EventArgs e)
{
...
// this is the struct that contain the List with all the information that I will show in the ListView
FinalScore=new Match();
...
// Now I call the function that will populate the ListView
ShowBestAction(FinalScore);
...
}
//This is the function that populate the ListView
private void ShowBestAction(Match Partita)
{
listViewHomeScorers.Items.Clear();
listViewVisitorsScorers.Items.Clear();
listViewMatch.Items.Clear();
listViewBestActions.Items.Clear();
Score Rete=new Score();
int Hgoal=0; int Vgoal=0;
for (int i=0;i
switch (Partita.Cronaca[i].GetCommentaryType())
{
case 0:
{
listViewBestActions.Items.Clear();
...
for (int j=conta-1;j>=0;j--)
{
ListViewItem item=new ListViewItem(Partita.Cronaca[i- j].GetCommentaryMinute().ToString(),Partita.Cronaca[i-j].GetCommentaryType());
item.SubItems.Add(Partita.Cronaca[i-j].GetCommentaryText());
listViewBestActions.Items.Add(item);
if (listViewBestActions.Items.Count>1) listViewBestActions.EnsureVisible(listViewBestActions.Items.Count-1);
listViewBestActions.Update();
System.Threading.Thread.Sleep(1000/trackbarVelocity.Value);
}
break;
}
case 1:
{
listViewBestActions.Items.Clear();
...
for (int j=conta-1;j>=0;j--)
{
ListViewItem item=new ListViewItem(Partita.Cronaca[i-j].GetCommentaryMinute().ToString(),Partita.Cronaca[i-j].GetCommentaryType());
item.SubItems.Add(Partita.Cronaca[i-j].GetCommentaryText());
listViewBestActions.Items.Add(item);
if (listViewBestActions.Items.Count>1) listViewBestActions.EnsureVisible(listViewBestActions.Items.Count-1);
listViewBestActions.Update();
System.Threading.Thread.Sleep(1000/trackbarVelocity.Value);
}
break;
}
case 2:
{
listViewBestActions.Items.Clear();
...
for (int j=conta-1;j>=0;j--)
{
ListViewItem item=new ListViewItem(Partita.Cronaca[i-j].GetCommentaryMinute().ToString(),Partita.Cronaca[i-j].GetCommentaryType());
item.SubItems.Add(Partita.Cronaca[i-j].GetCommentaryText());
listViewBestActions.Items.Add(item);
if (listViewBestActions.Items.Count>1) listViewBestActions.EnsureVisible(listViewBestActions.Items.Count-1);
listViewBestActions.Update();
System.Threading.Thread.Sleep(1000/trackbarVelocity.Value);
}
break;
}
case 3:
{
listViewBestActions.Items.Clear();
...
for (int j=conta-1;j>=0;j--)
{
ListViewItem item=new ListViewItem(Partita.Cronaca[i-j].GetCommentaryMinute().ToString(),Partita.Cronaca[i-j].GetCommentaryType());
item.SubItems.Add(Partita.Cronaca[i-j].GetCommentaryText());
listViewBestActions.Items.Add(item);
if (listViewBestActions.Items.Count>1) listViewBestActions.EnsureVisible(listViewBestActions.Items.Count-1);
listViewBestActions.Update();
System.Threading.Thread.Sleep(1000/trackbarVelocity.Value);
}
break;
}
case 4: break;
case 5:
{
listViewBestActions.Items.Clear();
...
for (int j=conta-1;j>=0;j--)
{
ListViewItem item=new ListViewItem(Partita.Cronaca[i-j].GetCommentaryMinute().ToString(),Partita.Cronaca[i-j].GetCommentaryType());
item.SubItems.Add(Partita.Cronaca[i-j].GetCommentaryText());
listViewBestActions.Items.Add(item);
if (listViewBestActions.Items.Count>1) listViewBestActions.EnsureVisible(listViewBestActions.Items.Count-1);
listViewBestActions.Update();
System.Threading.Thread.Sleep(1000/trackbarVelocity.Value);
}
break;
}
case 6: break;
case 7: break;
case 8:
{
listViewBestActions.Items.Clear();
...
for (int j=conta-1;j>=0;j--)
{
ListViewItem item=new ListViewItem(Partita.Cronaca[i-j].GetCommentaryMinute().ToString(),Partita.Cronaca[i-j].GetCommentaryType());
item.SubItems.Add(Partita.Cronaca[i-j].GetCommentaryText());
listViewBestActions.Items.Add(item);
if (listViewBestActions.Items.Count>1) listViewBestActions.EnsureVisible(listViewBestActions.Items.Count-1);
listViewBestActions.Update();
System.Threading.Thread.Sleep(1000/trackbarVelocity.Value);
}
break;
}
case 9:
{
listViewBestActions.Items.Clear();
...
for (int j=conta-1;j>=0;j--)
{
ListViewItem item=new ListViewItem(Partita.Cronaca[i-j].GetCommentaryMinute().ToString(),Partita.Cronaca[i-j].GetCommentaryType());
item.SubItems.Add(Partita.Cronaca[i-j].GetCommentaryText());
listViewBestActions.Items.Add(item);
if (listViewBestActions.Items.Count>1) listViewBestActions.EnsureVisible(listViewBestActions.Items.Count-1);
listViewBestActions.Update();
System.Threading.Thread.Sleep(1000/trackbarVelocity.Value);
}
...
for (int j=1;j
ListViewItem item=new ListViewItem(Partita.Cronaca[i+j].GetCommentaryMinute().ToString(),Partita.Cronaca[i+j].GetCommentaryType());
item.SubItems.Add(Partita.Cronaca[i+j].GetCommentaryText());
listViewBestActions.Items.Add(item);
if (listViewBestActions.Items.Count>1) listViewBestActions.EnsureVisible(listViewBestActions.Items.Count-1);
listViewBestActions.Update();
...
System.Threading.Thread.Sleep(1000/trackbarVelocity.Value);
}
...
break;
}
}
}
}
I hope that this will clear you what I did. If you have more question don't hesitate to ask me.
Nitesh KejriwalPosted Oct 28, 2012, 10:04 AM
pixel pixPosted Oct 28, 2012, 9:39 AM
However, unfortunately in this moment I have not much time... maybe tomorrow I'll post part of the code in order to show better what I do.
Nitesh KejriwalPosted Oct 26, 2012, 3:46 PM