Results 1 to 2 of 2

Thread: Problems with timers

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    1

    Problems with timers

    I have a problem with a project, where I manage 3 timers, one for moving items from a Listview to another listview (at certain time marks defined by a minutes database), and another timer to delete the moved items from the receiving Listview (at certain time marks given by the same DB, but different and idependently from the other timer).

    The problem is that they work perfectly until they just got blocked and they just stop doing their work without any explanation. I'm publishing my code so maybe someone can help me and tell me why do they just stop like that.

    VB Code:
    1. Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
    2.         'Utilizamos una variable estática que almacenará
    3.         'su valor cada vez que entremos en este evento
    4.         Dim lineas, lineas_desocupadas, lineas_ocupadas As Integer
    5.         Dim valor As Double
    6.         'velocidad = 0
    7.         valor = 0
    8.         lineas = Txt_num_lineas.Text
    9.         lineas_ocupadas = List_llamando.Items.Count
    10.         Txt_lineas_desocupadas.Text = lineas - lineas_ocupadas
    11.         Txt_ext_espera.Text = List_ext.Items.Count
    12.         Timer_duracion.Enabled = True
    13.         Timer_entrante.Enabled = True
    14.         If Radio_lenta.Checked = True Then
    15.             velocidad = 120
    16.             valor = 0.83
    17.         Else
    18.             If Radio_rapida.Checked = True Then
    19.                 velocidad = 80
    20.                 valor = 1.25
    21.             End If
    22.         End If
    23.         Static bteContador As Byte
    24.         If bteContador = velocidad Then
    25.             'Paramos el control Timer
    26.             Timer.Stop()
    27.             Timer_entrante.Stop()
    28.             Timer_duracion.Stop()
    29.             'Lo deshabilitamos para asegurarnos su parada
    30.             Timer.Enabled = False
    31.             Timer_entrante.Enabled = False
    32.             Timer_duracion.Enabled = False
    33.             MsgBox("Simulación terminada", MsgBoxStyle.Information, "Proyecto I")
    34.             Progress_simulacion.Value = 0
    35.         Else
    36.             'Incrementamos en una unidad la variable estática
    37.             bteContador = bteContador + 1
    38.             Progress_simulacion.Value = bteContador * valor
    39.         End If
    40.     End Sub
    41.  
    42.  
    43.     Private Sub Btn_Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Start.Click
    44.         If (Txt_num_lineas.Text = "") Or (Txt_num_lineas.Text <= 0) Then
    45.             MsgBox("Debe introducir un número mayor a 0 (cero) en el campo Número de Líneas", MsgBoxStyle.Critical, "Proyecto I")
    46.         End If
    47.         If (Radio_lenta.Checked = False) And (Radio_rapida.Checked = False) Then
    48.             MsgBox("Debe seleccionar una velocidad de simulación", MsgBoxStyle.Critical, "Proyecto I")
    49.         End If
    50.         Btn_Start.Enabled = False
    51.         Timer.Enabled = True
    52.        
    53.  
    54.     End Sub
    55.  
    56.  
    57.  
    58.  
    59.     Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.Click
    60.         Grp_internacionales.Visible = False
    61.         Grp_nacionales.Visible = False
    62.         Grp_totales.Visible = False
    63.         Grp_simulacion.Visible = True
    64.     End Sub
    65.  
    66.     Private Sub Timer_duracion_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer_duracion.Tick
    67.         Static bteContador_duracion As Byte
    68.         Dim ticker_duracion, bandera As Double
    69.         Dim banderas As String
    70.         If Radio_lenta.Checked = True Then
    71.             velocidad = 80
    72.         Else
    73.             If Radio_rapida.Checked = True Then
    74.                 velocidad = 60
    75.             End If
    76.         End If
    77.         If bteContador_duracion = velocidad Then
    78.             'Paramos el control Timer
    79.             'Timer_duracion.Stop()
    80.             'Lo deshabilitamos para asegurarnos su parada
    81.             'Timer_duracion.Enabled = False
    82.         Else
    83.             'Incrementamos en una unidad la variable estática
    84.             ticker_duracion = bteContador_duracion * 4
    85.             bandera = List_duracion_llamada.Items(0).Text
    86.             If (List_duracion_llamada.Items(0).Text <= ticker_duracion) Then
    87.                 banderas = List_llamando.Items(0).Text
    88.                 List_llamando.Items.RemoveAt(0)
    89.                 List_duracion_llamada.Items.RemoveAt(0)
    90.                 Txt_lineas_ocupadas.Text = List_llamando.Items.Count()
    91.                 Txt_lineas_desocupadas.Text = Txt_num_lineas.Text - List_llamando.Items.Count()
    92.                 Txt_llamadas_done.Text = Txt_llamadas_done.Text + 1
    93.             End If
    94.             bteContador_duracion = bteContador_duracion + 1
    95.         End If
    96.     End Sub
    97.  
    98.     Private Sub Timer_entrante_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer_entrante.Tick
    99.         Static bteContador_entrante As Byte
    100.         Dim ticker_entrante As Integer
    101.         If Radio_lenta.Checked = True Then
    102.             velocidad = 80
    103.         Else
    104.             If Radio_rapida.Checked = True Then
    105.                 velocidad = 60
    106.             End If
    107.         End If
    108.         If bteContador_entrante = velocidad Then
    109.             'Paramos el control Timer
    110.             'Timer_entrante.Stop()
    111.             'Lo deshabilitamos para asegurarnos su parada
    112.             'Timer_entrante.Enabled = False
    113.         Else
    114.             'Incrementamos en una unidad la variable estática
    115.             'ticker = bteContador_entrante
    116.             ticker_entrante = bteContador_entrante * 4
    117.             'List_minuto_llegada.Items(0).Selected = True
    118.             If (List_minuto_llegada.Items(0).Text <= ticker_entrante) Then
    119.                 'List_ext.Items(0).Selected = True
    120.                 If List_espera.Items.Count > 0 Then
    121.                     List_llamando.Items.Add(List_espera.Items(0).Text)
    122.                     List_espera.Items.RemoveAt(0)
    123.                     Txt_ext_espera.Text = List_espera.Items.Count()
    124.                     Txt_lineas_desocupadas.Text = Txt_num_lineas.Text - List_llamando.Items.Count()
    125.                     Txt_lineas_ocupadas.Text = List_llamando.Items.Count()
    126.                 End If
    127.  
    128.                 If List_llamando.Items.Count < Txt_num_lineas.Text Then
    129.                     List_llamando.Items.Add(List_ext.Items(0).Text)
    130.                     List_minuto_llegada.Items.RemoveAt(0)
    131.                     List_ext.Items.RemoveAt(0)
    132.                     Txt_lineas_desocupadas.Text = Txt_num_lineas.Text - List_llamando.Items.Count()
    133.                     Txt_lineas_ocupadas.Text = List_llamando.Items.Count()
    134.                 Else
    135.                     List_espera.Items.Add(List_ext.Items(0).Text)
    136.                     List_ext.Items.RemoveAt(0)
    137.                     List_minuto_llegada.Items.RemoveAt(0)
    138.                     Txt_ext_espera.Text = List_espera.Items.Count()
    139.                 End If
    140.             End If
    141.             bteContador_entrante = bteContador_entrante + 1
    142.         End If
    143.     End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Problems with timers

    Personally, I'm not usually prepared to read and decipher that much code in a post. Particularly with few comments and in an unfamiliar language. I would suggest putting break points on any lines that set the Enabled property to False or call Stop(). Then when execution stops you can determine what condition has caused it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width