Hola bueno vengo aqui se alguien me puede ayudar a como suspender una thread desde el vb,con el process hacker como lo hago ??
Yo e intentado esto pero no funciona
thread.sleep(1000)
pero como agrego la id o addres del proceso???
Hola,
Esto es vb.net, iría en otro subforo :P
De todas formas aquí tienes tu solución.
https://msdn.microsoft.com/es-es/library/system.threading.thread.suspend(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
Cita de: dante93150 en 29 Mayo 2016, 04:09 AM
Hola bueno vengo aqui se alguien me puede ayudar a como suspender una thread desde el vb,con el process hacker como lo hago ??
Yo e intentado esto pero no funciona
thread.sleep(1000)
pero como agrego la id o addres del proceso???
No se suspende, se queda esclavo. Mejor usar timer.
Timer1.Start(); para empezar y Timer1.Stop(); para parar cuando quieras.
Cita de: fary en 29 Mayo 2016, 07:53 AMDe todas formas aquí tienes tu solución.
https://msdn.microsoft.com/es-es/library/system.threading.thread.suspend(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
Yo creo que él más bien se refiere a suspender la ejecución de un hilo por un tiempo definido como hace el método Thread.Sleep(), pero pudiendo especificar un identificador del hilo.
Cita de: dante93150 en 29 Mayo 2016, 04:09 AM
thread.sleep(1000)
como agrego la id o addres del proceso???
No puedes especificar un thread-id, el método
Thread.Sleep() solamente afecta al hilo desde donde se invocó a dicha función, de hecho las funciones Win32
Sleep y
SleepEx tienen el mismo comportamiento, simplemente NO es posible ...de forma "nativa".
Pero puedes recurrir a las funciones Win32 relacionadas (SuspendThread, ResumeThread), aplicando metodologías asincrónicas.
Te dejo esta solución que he elaborado (lo testeé con el thread-id del UI thread):
Modo de empleo:
Dim threadId As Integer = GetCurrentThreadId().
SleepThread(threadId, TimeSpan.FromSeconds(5))
Código fuente:
Public Shared Sub SleepThread(ByVal threadId As Integer, ByVal timespan As TimeSpan)
Dim hThread As IntPtr
Dim win32Err As Integer
Dim suspendFunc As Func(Of Integer) =
Function() As Integer ' Returns the previous suspend count for the thread.
Dim suspendCount As Integer
Debug.WriteLine("Sleeping...")
Thread.Sleep(timespan)
Debug.WriteLine("Resuming thread...")
suspendCount = ResumeThread(hThread)
CloseHandle(hThread)
Return suspendCount
End Function
hThread = OpenThread(ThreadAccessRights.SuspendResume Or ThreadAccessRights.Terminate, True, threadId)
win32Err = Marshal.GetLastWin32Error()
If (hThread = IntPtr.Zero) Then
Throw New Win32Exception(win32Err)
Else
Debug.WriteLine("Pausing thread...")
Dim suspendTask As Task(Of Integer) = Task.Factory.StartNew(Of Integer)(suspendFunc)
SuspendThread64(hThread)
End If
End Sub
P/Invoking:
<SuppressUnmanagedCodeSecurity>
<DllImport("kernel32.dll", SetLastError:=False)>
Public Shared Function GetCurrentThreadId(
) As <MarshalAs(UnmanagedType.U4)> Integer
End Function
<DllImport("kernel32.dll", SetLastError:=True)>
Public Shared Function OpenThread(
<MarshalAs(UnmanagedType.I4)> ByVal dwDesiredAccess As ThreadAccessRights,
<MarshalAs(UnmanagedType.Bool)> ByVal bInheritHandle As Boolean,
<MarshalAs(UnmanagedType.U4)> ByVal dwThreadId As Integer
) As IntPtr
End Function
<DllImport("kernel32.dll", EntryPoint:="Wow64SuspendThread", SetLastError:=True)>
Public Shared Function SuspendThread32(
<MarshalAs(UnmanagedType.SysInt)> ByVal hThread As IntPtr
) As Integer
End Function
<DllImport("kernel32.dll", EntryPoint:="SuspendThread", SetLastError:=True)>
Public Shared Function SuspendThread64(
<MarshalAs(UnmanagedType.SysInt)> ByVal hThread As IntPtr
) As Integer
End Function
<DllImport("kernel32.dll", SetLastError:=True)>
Public Shared Function ResumeThread(
<MarshalAs(UnmanagedType.SysInt)> ByVal hThread As IntPtr
) As Integer
End Function
<DllImport("kernel32.dll", SetLastError:=True)>
Public Shared Function CloseHandle(
<MarshalAs(UnmanagedType.SysInt)> ByVal hObject As IntPtr
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<Flags>
Public Enum ThreadAccessRights As Integer
Terminate = &H1
SuspendResume = &H2
End Enum
PD: Todo esto lo puedes encontrar en mi API ElektroKit (en mi firma, aquí abajo).
Saludos.