OnTimedEvent
-
:doh:HI , I want one function to be called repltedly after a perticular interval. SO i have implemented OnTimedEvent. In that I called my function IsFinish. Isfinish contains some more function calls. If i call Isfinish from a button and get the values after some interval it is workig fine. but if I call this function from OnTimedEvent it is returning null. Please guide. ciacia
-
:doh:HI , I want one function to be called repltedly after a perticular interval. SO i have implemented OnTimedEvent. In that I called my function IsFinish. Isfinish contains some more function calls. If i call Isfinish from a button and get the values after some interval it is workig fine. but if I call this function from OnTimedEvent it is returning null. Please guide. ciacia
There's no such event in the .NET Framework. Which Timer did you use? There are three in the .NET BCL: System.Threading.Timer System.Timers.Timer System.Windows.Forms.Timer
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
There's no such event in the .NET Framework. Which Timer did you use? There are three in the .NET BCL: System.Threading.Timer System.Timers.Timer System.Windows.Forms.Timer
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
:doh:HI , I want one function to be called repltedly after a perticular interval. SO i have implemented OnTimedEvent. In that I called my function IsFinish. Isfinish contains some more function calls. If i call Isfinish from a button and get the values after some interval it is workig fine. but if I call this function from OnTimedEvent it is returning null. Please guide. ciacia
The System.Timers.Timer uses a seperate thread to call the timer elapsed handler code. If your code is trying to get data from user controls to do it's work, it won't get any data. This is because you can only use a controls methods and properties on the thread that the control was created on. Let's see your OnTimedEvent method...
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
The System.Timers.Timer uses a seperate thread to call the timer elapsed handler code. If your code is trying to get data from user controls to do it's work, it won't get any data. This is because you can only use a controls methods and properties on the thread that the control was created on. Let's see your OnTimedEvent method...
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Please allow me to repeat myself: Let's see your OnTimedEvent method code.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Please allow me to repeat myself: Let's see your OnTimedEvent method code.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Private Sub OnTimedEvent(ByVal source As Object, ByVal e As ElapsedEventArgs) IsFinished() End Sub Function IsFinished() As Boolean Dim strLength As String strLength = New String("255") Dim strPosition As String Dim IntLentgh As Integer Dim IntPosition As Integer strPosition = New String("255") mciSendString("status track length", strLength, 255, 0) mciSendString("status track position", strPosition, 255, 0) IntLentgh = CInt(strLength) IntPosition = CInt(strPosition) If IntPosition >= IntLentgh Then notifyTimer.Stop() MsgBox(strPosition) MsgBox(strLength) End If End Function
-
Private Sub OnTimedEvent(ByVal source As Object, ByVal e As ElapsedEventArgs) IsFinished() End Sub Function IsFinished() As Boolean Dim strLength As String strLength = New String("255") Dim strPosition As String Dim IntLentgh As Integer Dim IntPosition As Integer strPosition = New String("255") mciSendString("status track length", strLength, 255, 0) mciSendString("status track position", strPosition, 255, 0) IntLentgh = CInt(strLength) IntPosition = CInt(strPosition) If IntPosition >= IntLentgh Then notifyTimer.Stop() MsgBox(strPosition) MsgBox(strLength) End If End Function
You're making a mistake with these strings ("255"). You're not creating an empty string 255 characters wide. YOu're making a string 3 characters wide, containging "255". Then in your mciSendString call, you're passing this string in parameters2, but in parameter 3, you're telling mciSendString that the string buffer you just passed in was 255 characters long. No, it's not, it's 3 characters long! I think you're looking for this:
Dim strBuffer As New StringBuilder(255)
On top of that, you're completely ignoring the return value comming back from the call to mciSendString. You REALLY need to pay attention to that value:
Dim rc As Integer rc = mciSendString("status track length", strBuffer, 255, Nothing) If rc > 0 Then ' An error occured! End If
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
You're making a mistake with these strings ("255"). You're not creating an empty string 255 characters wide. YOu're making a string 3 characters wide, containging "255". Then in your mciSendString call, you're passing this string in parameters2, but in parameter 3, you're telling mciSendString that the string buffer you just passed in was 255 characters long. No, it's not, it's 3 characters long! I think you're looking for this:
Dim strBuffer As New StringBuilder(255)
On top of that, you're completely ignoring the return value comming back from the call to mciSendString. You REALLY need to pay attention to that value:
Dim rc As Integer rc = mciSendString("status track length", strBuffer, 255, Nothing) If rc > 0 Then ' An error occured! End If
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
OHHH, thaks a lot for your suggestion. I tried stringBuilder but it is not recognizing it I have also imported system.text.stringbuilder .
No, you Import System.Text, not System.Text.StringBuilder.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007