Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. how to run the function 10 second later ? [modified]

how to run the function 10 second later ? [modified]

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cheeken2u
    wrote on last edited by
    #1

    I need the button disappear after 5 second the window form is load, how i do this ? Chee ken

    T 1 Reply Last reply
    0
    • C cheeken2u

      I need the button disappear after 5 second the window form is load, how i do this ? Chee ken

      T Offline
      T Offline
      Tirthadip
      wrote on last edited by
      #2

      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....."

      C 1 Reply Last reply
      0
      • T Tirthadip

        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....."

        C Offline
        C Offline
        cheeken2u
        wrote on last edited by
        #3

        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

        T T 2 Replies Last reply
        0
        • C cheeken2u

          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

          T Offline
          T Offline
          Tirthadip
          wrote on last edited by
          #4

          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....."

          1 Reply Last reply
          0
          • C cheeken2u

            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

            T Offline
            T Offline
            TwoFaced
            wrote on last edited by
            #5

            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
            
            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups