Click here to Skip to main content
15,794,850 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
<pre>Flags()> _  
    Public Enum ThreadAccess As Integer 
        TERMINATE = (&H1)  
        SUSPEND_RESUME = (&H2)  
        GET_CONTEXT = (&H8)  
        SET_CONTEXT = (&H10)  
        SET_INFORMATION = (&H20)  
        QUERY_INFORMATION = (&H40)  
        SET_THREAD_TOKEN = (&H80)  
        IMPERSONATE = (&H100)  
        DIRECT_IMPERSONATION = (&H200)  
    End Enum 
 
    Private Declare Function OpenThread Lib "kernel32.dll" (ByVal dwDesiredAccess As ThreadAccess, ByVal bInheritHandle As Boolean, ByVal dwThreadId As UInteger) As IntPtr  
    Private Declare Function SuspendThread Lib "kernel32.dll" (ByVal hThread As IntPtr) As UInteger  
    Private Declare Function ResumeThread Lib "kernel32.dll" (ByVal hThread As IntPtr) As UInteger  
    Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hHandle As IntPtr) As Boolean 
 
    Private Sub SuspendProcess(ByVal process As System.Diagnostics.Process)  
        For Each t As ProcessThread In process.Threads  
            Dim th As IntPtr  
 
            th = OpenThread(ThreadAccess.SUSPEND_RESUME, False, t.Id)  
            If th <> IntPtr.Zero Then 
                SuspendThread(th)  
                CloseHandle(th)  
            End If 
        Next 
    End Sub 
 
    Private Sub ResumeProcess(ByVal process As System.Diagnostics.Process)  
        For Each t As ProcessThread In process.Threads  
            Dim th As IntPtr  
 
            th = OpenThread(ThreadAccess.SUSPEND_RESUME, False, t.Id)  
            If th <> IntPtr.Zero Then 
                ResumeThread(th)  
                CloseHandle(th)  
            End If 
        Next 
    End Sub 


What I have tried:

how do i create a thread with a pause with a button control to resume
Dim work1 As System.Threading.Thread = New Threading.Thread(AddressOf Some task)
Posted
Updated 27-Jan-19 1:07am

1 solution

You can use Thread.Sleep() although this is not considered good practice, it will freeze your application: https://www.dotnetperls.com/sleep-vbnet[^]

See answer here for an alternative: Wait .5 seconds before continuing code VB.net - Stack Overflow[^]
And also: ManualResetEvent Class (System.Threading) | Microsoft Docs[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900