Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Visual Studio 2008 - VB - Background work  (Read 10235 times)

0 Members and 1 Guest are viewing this topic.

devcom

    Topic Starter


    Apprentice

    Thanked: 37
    Re: Visual Studio 2008 - VB - Background work
    « Reply #15 on: January 05, 2009, 07:56:06 AM »
    YAY ! ;D Got this done allready  ;D

    Found this on internet:

    Code: [Select]
    Public Class Form1
        Dim accessLock As New Object
        Dim endThread As Boolean = False
        Dim PlayThread As New System.Threading.Thread(AddressOf CodeInThread)

        Private Sub CodeInThread()
            Dim keepRunning As Boolean = True

            While keepRunning 'keeps thread running forever


                'We lock, because that is one way of ensuring that no other thread
                'is accessing the same variables at the same time
                SyncLock accessLock
                    If endThread Then
                        keepRunning = False
                    End If
                End SyncLock
            End While 'loop forever until keepRunning = False

            'keepRunning now equals false
            'put cleanup code here

            'when the sub finishes, the thread ends
        End Sub

        Public Sub StopThread()
            SyncLock accessLock
                endThread = True
            End SyncLock
        End Sub

        Private Sub StopBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopBtn.Click
            StopThread()
        End Sub

        Private Sub StartBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartBtn.Click
            PlayThread.Start()
        End Sub
    End Class

    everythink its working now thanks for helping  ;D ::)
    Download: Choice.exe

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Visual Studio 2008 - VB - Background work
    « Reply #16 on: January 05, 2009, 09:15:56 AM »
    lol, that's the method I just described  ;D
    I was trying to dereference Null Pointers before it was cool.

    devcom

      Topic Starter


      Apprentice

      Thanked: 37
      Re: Visual Studio 2008 - VB - Background work
      « Reply #17 on: January 05, 2009, 11:43:44 AM »
      lol, didnt know you are talking about that  ::)
      Download: Choice.exe

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Visual Studio 2008 - VB - Background work
      « Reply #18 on: January 05, 2009, 11:45:20 AM »
      well, it uses a form-level variable to flag when the thread should end. that was what I meant.

      good to hear you got it workin.

      what is this for? Just curious.
      I was trying to dereference Null Pointers before it was cool.

      devcom

        Topic Starter


        Apprentice

        Thanked: 37
        Re: Visual Studio 2008 - VB - Background work
        « Reply #19 on: January 05, 2009, 12:17:52 PM »
        Its should be a metronome, that used when you play guitar  ;)
        Download: Choice.exe