• Domingo 5 de Mayo de 2024, 19:02

Autor Tema:  Problema Con Timers  (Leído 1417 veces)

tyttan

  • Nuevo Miembro
  • *
  • Mensajes: 7
    • Ver Perfil
Problema Con Timers
« en: Viernes 19 de Agosto de 2005, 19:34 »
0
Hola,

Estoy utilzando un timer para llamar ejecutar una función cada 5 minutos.

El tema es que esa función funciona perfectamente cuando se le llama de manera manual.

Pero al llamarle desde la rutina del timers, una vez realizada, y al intentar cerrar la ventana, esta se queda colgada.

He conseguido solucionarlo, quitando de la función referncias a una label, que la hacia visible....

Como es esto posible? que deje de funcionar por eso?? Hay que hacer algo especial a la hora de trabajar con timers??

Gracias

JuanK

  • Miembro de ORO
  • ******
  • Mensajes: 5393
  • Nacionalidad: co
    • Ver Perfil
    • http://juank.io
Re: Problema Con Timers
« Respuesta #1 en: Sábado 20 de Agosto de 2005, 17:02 »
0
cuando trabajas con hilos ( como es tu caso aunque no se vea de inmediato) suelen pasar esas cosas...

postea tucodigo y haremos los ajustes pertinentes.
[size=109]Juan Carlos Ruiz Pacheco
[/size]
Microsoft Technical Evangelist
@JuanKRuiz
http://juank.io

tyttan

  • Nuevo Miembro
  • *
  • Mensajes: 7
    • Ver Perfil
Re: Problema Con Timers
« Respuesta #2 en: Lunes 22 de Agosto de 2005, 09:32 »
0
public void InitializeTimer()
   {
      this.timerClock.Elapsed += new ElapsedEventHandler(OnTimer);
      this.timerClock.Interval = 1000;
   }
   

public void OnTimer(Object source, ElapsedEventArgs e)
   {
      try
      {
         //this.clockTime++;
         //long countdown = this.alarmTime - this.clockTime ;
         
         if( this.contador != 0 )
         {
            
            this.contador--;
            //this.textBoxTiempo.Text = contador.ToString();
            this.textBoxTiempo.Text = this.secondsToTime(contador);
               
         }

         //SALTA TEMPORIZADOR
         if( this.contador == 0 && this.minutos  != 0 && this.ocupado == false )
         {   
            this.timerClock.Enabled= false;
            //this.timerClock.Stop();
            //this.textBoxTiempo.Text = "salta temporizador";
            //this.textBoxTiempo.Text = contador.ToString();
            contador = minutos ;
            MonitorizaAlarmas();




            this.timerClock.Enabled= true;
            //this.timerClock.Interval = 60000;
   
         }
         if( this.contador == 0 && this.minutos  != 0 && this.ocupado == true )
         {
            contador = minutos ;
         }

      }
      catch( Exception ex )
      //catch
      {
         MessageBox.Show("OnTimer():"  + ex.Message  );
      }           
      
   }


Y aqui la función MOnitoriza Alarmas, con las instrucciones que hacen que se cuelgue al CERRAR!!

private void MonitorizaAlarmas()
   {
      string respuesta;
      string query;
      string ultimapantalla = "";
      char comillas = '"';
      this.ocupado = true;
      int numeroMedidas= 0;

      

      // 0 = OK ; 1 = RIESGO; 2 = CRITICO
      int [] estado = new int [10];
      int [] estado_anterior = new int [10];

      System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

      
         
      // Linea del fichero
      int linea = this.lineafichero;

      this.buttonIniciar.Enabled = false;
      this.panelIntervalo.Enabled = false;

      //barra y label


      if (this.manual == true)
      {
         this.panelMon.Visible = true;
      }
      else
      {
      this.labelMon.Visible = true;//      }


      //this.labelMon.Visible = true;
      //this.progressBarMidiendo.Visible = true;


      

         // BARRA DE PROGRESO:

         for (int i = 0; i < 10; i++)
         {   
            if (alarmas.seleccion == true)
            {
               numeroMedidas++;
            }
         }
      

         this.progressBarMidiendo.Value = 0;
         this.progressBarMidiendo.Maximum = numeroMedidas * 2;
         //this.progressBarMidiendo.Maximum = 20;
         //this.panelMon.Visible = true;

      .
.
.
.
.
.
.


         for (int i = 0; i < 10; i++)
         {

            //Solo mide las seleccionadas.
            if (alarmas.seleccion == true)
            {
               
               int indice_inst = alarmas.num_instruccion;


                  this.Refresh();
                  //Espera x milisegs en cada cambio de pantalla
                  Thread.Sleep(3000);
                     
                  

   
   
   .
.
.
.
.
.

                  
   
      
         this.labelMon.Visible = false;
         this.progressBarMidiendo.Enabled = false;
         //this.progressBarMidiendo.Visible = false;
         
         //this.toolBar1.Buttons[1].Enabled = true;
         
         
         
         this.toolBarButtonVerLog.Enabled = true;
         this.menuItemVerLog.Enabled = true;
         
         this.buttonIniciar.Enabled = true;
         this.panelIntervalo.Enabled = true;
         
         //this.Refresh();
         //Thread.Sleep(1000);

         if (this.manual == true)
         {
            this.panelMon.Visible = false;
         }
         else
         {
            //this.labelMon.Visible = false;
         }
         
         
         
         
         //this.panelMidiendo.Visible = false;
         //barra y label
         
         this.ocupado = false;
      
      }
      
      //this.Refresh();

      this.ocupado = false;

   }

LAS INSTRUCCIONES QUE CUANDO SE PONEN LO CUELGAN SON LAS RELATIVAS A UN PANEL, O ETIQUETA QUE PONE MIDIENDO... CUANDO SE EJECUTA ESTA FUNCIÓN.

JuanK

  • Miembro de ORO
  • ******
  • Mensajes: 5393
  • Nacionalidad: co
    • Ver Perfil
    • http://juank.io
Re: Problema Con Timers
« Respuesta #3 en: Lunes 22 de Agosto de 2005, 15:16 »
0
HOla, bueno realmente me refereia a que anexaras un archivo .zip  en el post ya que asi puedo revisar el codigo completo.
[size=109]Juan Carlos Ruiz Pacheco
[/size]
Microsoft Technical Evangelist
@JuanKRuiz
http://juank.io