Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All,

Thanks in advance. After enough googling and try and error I decided to write very simple question here.

I am working on TASK where I want to display vehicle numbers on display like railway station where LED screens shows Vehicle Numbers.

I have designed Windows Form. with one gridview. In this form I have added only one gridview.

According to requirement I have to show only 3 records at a time.

My problem is first three records are getting displayed well after that gridview is not adding next three records.

Please check below code of load vehicle data method :I called this method from timer tick event after 30 seconds. I have also used process status variable which checks that process is in progress or not. If process is not in progress then only timer calls that load vehicle data method
C#
private void loadVehicleNumbers()
       {
           try
           {
               processStatus = 1;
                   DataTable dtVehicleData = ApplicationManager.DAL.getVehicleDetailsWhoseCommissioningIsNotDone();
                   MessageBox.Show("Number of vehicles : "+dtVehicleData.Rows.Count);
                   if (dtVehicleData.Rows.Count > 0)
                   {
                       this.dgv_vehicleNumbers.Rows.Clear();

                       int j = 0;
                       for (int i = 0; i < dtVehicleData.Rows.Count; i++)
                       {
                           if (j == 3)
                           {
                               Thread.Sleep(10000);

                               j = 0;
                               dgv_vehicleNumbers.Rows.Clear();
                               dgv_vehicleNumbers.Update();
                               dgv_vehicleNumbers.Refresh();

                           }

                           string vehicleNumber = dtVehicleData.Rows[i]["VEHICLE_NUMBER"].ToString();
                           string EntryNumber = dtVehicleData.Rows[i]["Entry_NUMBER"].ToString();
                           string drivingLicensenumber = dtVehicleData.Rows[i]["Driver_NUMBER"].ToString();
                           string driver_Name = dtVehicleData.Rows[i]["DRIVER_NAME"].ToString();

                           //MessageBox.Show("Driver License Number :" + drivingLicensenumber);

                           int temp = i + 1;
                           string[] row1 = new string[] { "" + temp, vehicleNumber, driver_Name };
                           this.dgv_vehicleNumbers.Rows.Add(row1);

                           j++;
                           dgv_vehicleNumbers.Update();
                           dgv_vehicleNumbers.Refresh();
                           if (i == (dtVehicleData.Rows.Count - 1))
                           {
                               Thread.Sleep(10000);
                           }

                       }
                   }
                   else
                   {
                       Thread.Sleep(10000);
                   }
                   processStatus = 0;

           }
           catch (Exception ex)
           {
               frmHZLHome.WriteErrorLog(DateTime.Now.ToString("dd/MMM/yyyy HH:mm:ss") + ",Driver Room LED Display ," + ex.Message);
           }
       }

private void timer1_Tick(object sender, EventArgs e)
       {
           if (processStatus == 0)
           {
               MessageBox.Show("Loading  vehicles");
               loadVehicleNumbers();
           }
       }
Posted
Updated 1-Sep-15 23:18pm
v2
Comments
j snooze 2-Sep-15 17:34pm    
pretty sure if you set a break point in the method and debug you will find the issue quickly. i'm not understanding what you are trying to accomplish. You want to show 3 records and you say that is working well, but not the next 3? so you should be showing 6 now or a different 3 records? What tells your method not to grab the same 3 records over and over?
[no name] 3-Sep-15 1:32am    
Thread.Sleep();

which results in not responding state of application

1 solution

Hello,

All never use Thread.Sleep(); in windows form application.

Use timers as per your requirement.
 
Share this answer
 

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