exceptions in timer dependent class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Przemo

    exceptions in timer dependent class

    I have Class1 which performs some data calculations on
    System.Timers.T imer.Elapsed event.

    Public Class Class1
    Private WithEvents tmrReadSerialDa ta As New
    System.Timers.T imer

    Public Sub New()
    tmrReadSerialDa ta.Interval = 1000
    End Sub

    Public Sub StartIt()
    tmrReadSerialDa ta.Start()
    End Sub

    Public Sub StopIt()
    tmrReadSerialDa ta.Stop()
    End Sub

    Private Sub tmrReadSerialDa ta_Tick(ByVal sender As
    System.Object, ByVal e As System.Timers.E lapsedEventArgs )
    Handles tmrReadSerialDa ta.Elapsed

    ' This line should throw an exception because of
    ' different culture setting (2.54 in spite of 2,54)
    ' but it doesn't, exits sub and Beep is not performed
    Dim a As Double = Double.Parse("2 .54", New
    Globalization.C ultureInfo("pl-PL"))
    Beep

    End Sub

    Public Sub Test()

    ' Ta linia nie powoduje błędu - konwersja liczby
    zapisanej w ustawieniach regionalnych USA
    Dim b As Double = Double.Parse("2 .54", New
    Globalization.C ultureInfo("en-US"))
    Dim a As Double = Double.Parse("2 .54")
    Beep()

    End Sub

    End Class


    When I use this object from my WinForm and click button
    which performs Class1.StartIt, tmrReadSerialDa ta_Tick
    exits on line which should cause an exception but without
    it!
    When I place same code in my WinForm exceprion occures.

    1. Is that exception caused or not?
    2. Is Timer.Elapsed method run in different thread?
    3. What to do to be informed of such exceptions in run-
    time (program can be stopped but with normal info about
    exception) - I was looking for long time what was the
    reason for not executing some code after it.

    Thank you
  • Cor Ligthert

    #2
    Re: exceptions in timer dependent class

    Przemo,

    I am curious, what is the reason you are using the C# code in your VBNet
    project for conversion, while some of the the more advantage C# users would
    like to have those powerfull VBNet convert methods?

    Cor


    Comment

    • Ledder H.

      #3
      Re: exceptions in timer dependent class

      Sorry, but did you help Przemo?
      I can't understand you

      best regards
      [color=blue]
      >-----Original Message-----
      >Przemo,
      >
      >I am curious, what is the reason you are using the C#[/color]
      code in your VBNet[color=blue]
      >project for conversion, while some of the the more[/color]
      advantage C# users would[color=blue]
      >like to have those powerfull VBNet convert methods?
      >
      >Cor
      >
      >
      >.
      >[/color]

      Comment

      • Cor Ligthert

        #4
        Re: exceptions in timer dependent class

        > Sorry, but did you help Przemo?[color=blue]
        > I can't understand you[/color]

        I thought this is a newsgroup, not a kind of helpdesk.

        Now I can't understand you?

        Cor



        Comment

        • Przemo

          #5
          Re: exceptions in timer dependent class

          Thanks for replay, but I don't nderstad.
          Am I using C# code?? I am using VB.NET.
          This code compiles in vb.net project with no errors.
          So what did you mean?
          [color=blue]
          >-----Original Message-----
          >Przemo,
          >
          >I am curious, what is the reason you are using the C#[/color]
          code in your VBNet[color=blue]
          >project for conversion, while some of the the more[/color]
          advantage C# users would[color=blue]
          >like to have those powerfull VBNet convert methods?
          >
          >Cor
          >
          >
          >.
          >[/color]

          Comment

          • Cor Ligthert

            #6
            Re: exceptions in timer dependent class

            Przemo,[color=blue]
            > Thanks for replay, but I don't nderstad.
            > Am I using C# code?? I am using VB.NET.
            > This code compiles in vb.net project with no errors.
            > So what did you mean?
            >[/color]
            In that are you right, however you limit yourself in my opinion to a very
            small subset. When you would do by instance this,

            For i = 1 to 1000
            a +=5
            Next

            And than ask something as why is this not efficient to a newsgroup.

            It is using as well VBNet code, however most people use
            a = 5*1000

            So I was curious why you are doing that?

            Cor



            Comment

            • Przemo

              #7
              Re: exceptions in timer dependent class

              My code was only example (small peace of my Comm parsing
              Class).
              I didn't want to know if it is efficient or not.
              I couldn't understand why this line which should cause
              exception do not do it in my class.

              Write if you can help.
              [color=blue]
              >-----Original Message-----
              >Przemo,[color=green]
              >> Thanks for replay, but I don't nderstad.
              >> Am I using C# code?? I am using VB.NET.
              >> This code compiles in vb.net project with no errors.
              >> So what did you mean?
              >>[/color]
              >In that are you right, however you limit yourself in my[/color]
              opinion to a very[color=blue]
              >small subset. When you would do by instance this,
              >
              >For i = 1 to 1000
              > a +=5
              >Next
              >
              >And than ask something as why is this not efficient to a[/color]
              newsgroup.[color=blue]
              >
              >It is using as well VBNet code, however most people use
              >a = 5*1000
              >
              >So I was curious why you are doing that?
              >
              >Cor
              >
              >
              >
              >.
              >[/color]

              Comment

              • Cor Ligthert

                #8
                Re: exceptions in timer dependent class

                Przemo,

                This throws an exception when I try this.

                Private Sub Button1_Click(B yVal sender As System.Object, _
                ByVal e As System.EventArg s) Handles Button1.Click
                ' This line should throw an exception because of
                ' different culture setting (2.54 in spite of 2,54)
                ' but it doesn't, exits sub and Beep is not performed
                Dim a As Double = Double.Parse("2 .54", New
                Globalization.C ultureInfo("pl-PL"))
                Beep()
                End sub

                I hope this helps?

                Cor


                Comment

                Working...