Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day guys, I'm a semi-intermediate here in c#. Actually, the said topic name it won't work with my codes implemented, i need some help on how to improve my timer tick procedure code as shown what I've tried below.

What I have tried:

here is my code as follows.

private void timer1_Tick(object sender, EventArgs e)
        {
            statmessage();

            int i = listBox1.SelectedItems.Count + 1;

          if (i < 0)
            {
                var exp = (EItem)listBox1.Items[i];
                var timeVisible = DateTime.Now - exp.Added;
                if (timeVisible.TotalSeconds > 5)
                    if (counter == 100)
                    {
                   
                    SendMessage();
                    counter = counter - 1;
                    ++i;
                    }
                    else if (counter <= 0)
                    {

                    statmessage();
                    }
                
            }

        }


Your feedback is highly appreciated and will help to improve the said concern, Thank you very much
Posted
Updated 31-Jan-19 2:11am
Comments
Richard MacCutchan 31-Jan-19 4:34am    
The value of i can never be less than 0.
Richard Deeming 4-Feb-19 14:12pm    
That sounds like a challenge! Time to build a machine capable of coping with int.MaxValue items in a single listbox. :)

1 solution

As Richard mentioned in the comments, it should be pretty obvious, right? All of your code is inside of an if statement that will only run when i is less than 0. However, I is set to the count of the listbox items. How can I ever be less than 0?

Simple debugging would have found this much faster than the time it took you to post the question. :)
 
Share this answer
 
Comments
Richard Deeming 4-Feb-19 14:11pm    
"... I is set to the count of the listbox items ..."

It's actually set to one more than the count. So technically, it could be less than zero if there were int.MaxValue items in the listbox - assuming the OS hadn't given up by that point. :)
ZurdoDev 4-Feb-19 15:15pm    
That might be a little beyond the complexity of this question. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900