how to run the function 10 second later ? [modified]
-
I need the button disappear after 5 second the window form is load, how i do this ? Chee ken
First of all there is no relation between your subjectline and problem....... Whatsoever... Take a global timer variable say myTimer as ....
Dim WithEvents myTimer As New Timers.Timer
then....put this code in your form load event..With myTimer .AutoReset = True .Interval = 5000 .Start() End With
finally write following code in Timer's Elapse event like...Public Sub myTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles myTimer.Elapsed Button1.Visible = False myTimer.Close() End Sub
Tirtha "A man can ride on your back only when it is bent....."
-
First of all there is no relation between your subjectline and problem....... Whatsoever... Take a global timer variable say myTimer as ....
Dim WithEvents myTimer As New Timers.Timer
then....put this code in your form load event..With myTimer .AutoReset = True .Interval = 5000 .Start() End With
finally write following code in Timer's Elapse event like...Public Sub myTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles myTimer.Elapsed Button1.Visible = False myTimer.Close() End Sub
Tirtha "A man can ride on your back only when it is bent....."
-
Cross-thread operation not valid: Control 'Button1' accessed from a thread other than the thread it was created on. Why have this error point to "Button1.Visible = False" this line ? Regards, Chee ken
it is not at all any coding problem.......it works fine....but check what you are doing with that particular button...whether any other process is calling or referencing your control or not.... see here.......... http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=9756&SiteID=1[^]
Tirtha "A man can ride on your back only when it is bent....."
-
Cross-thread operation not valid: Control 'Button1' accessed from a thread other than the thread it was created on. Why have this error point to "Button1.Visible = False" this line ? Regards, Chee ken
The code posted uses the Timers.Timer object which runs on a separate thread. Trying to change UI elements like visibility of a button will generate a cross thread error. It's unsafe to access controls from a thread that didn't create that control. Instead try using the forms.timer.
Dim WithEvents myTimer As New Windows.Forms.Timer Public Sub myTimer\_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles myTimer.Tick Button1.Visible = False myTimer.Stop() End Sub Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With myTimer .Interval = 5000 .Start() End With End Sub