E
elziko
This is a repost from microsoft.public.dotnet.languages.vb but I had no luck
there so maybe this is a better place to ask?
I'd like to 'pause' a process that has nothing to do with my application. To
do this I intend to suspend every thread in the process.
So far I have managed to get the System.Diagnostics.Process and all the
ProcessThreads running under that. My first question is, what's the
relationship between a ProcessThread and a Thread? From what I have read for
every real thread there is a managed thread. Does this mean their IDs are
the same?
I have then used the OpenThread API to get the handle for the thread using
the ID from each ProcessThread. However the handle that OpenThread seems to
return is the same for each ProcessThread. Infact the return value is always
8589934592 which incidently is the number of bits in a gigabyte(!).
The next plan is to use the SuspendThread API to suspend each of these
threads which I can't do until I'm sure I'm getting the correct Thread
handles.
Does any one have any comments or advice (especially on keeping as much of
the code as possible managed) on how to get this working?
Here is my current code in case that helps:
Declare Function OpenThread Lib "kernel32" (ByVal dwDesiredAccess As Long,
ByVal bInheritHandle As Boolean, ByVal dwThreadId As Long) As Long
and...
Dim AllProcesses As Process() =
System.Diagnostics.Process.GetProcessesByName("MyProcess")
Dim MyProcess As Process = AllProcesses(0)
For Each ProcessThread As ProcessThread In ActiveSyncProcess.Threads
Console.WriteLine(OpenThread(1, True, ProcessThread.Id))
Next
there so maybe this is a better place to ask?
I'd like to 'pause' a process that has nothing to do with my application. To
do this I intend to suspend every thread in the process.
So far I have managed to get the System.Diagnostics.Process and all the
ProcessThreads running under that. My first question is, what's the
relationship between a ProcessThread and a Thread? From what I have read for
every real thread there is a managed thread. Does this mean their IDs are
the same?
I have then used the OpenThread API to get the handle for the thread using
the ID from each ProcessThread. However the handle that OpenThread seems to
return is the same for each ProcessThread. Infact the return value is always
8589934592 which incidently is the number of bits in a gigabyte(!).
The next plan is to use the SuspendThread API to suspend each of these
threads which I can't do until I'm sure I'm getting the correct Thread
handles.
Does any one have any comments or advice (especially on keeping as much of
the code as possible managed) on how to get this working?
Here is my current code in case that helps:
Declare Function OpenThread Lib "kernel32" (ByVal dwDesiredAccess As Long,
ByVal bInheritHandle As Boolean, ByVal dwThreadId As Long) As Long
and...
Dim AllProcesses As Process() =
System.Diagnostics.Process.GetProcessesByName("MyProcess")
Dim MyProcess As Process = AllProcesses(0)
For Each ProcessThread As ProcessThread In ActiveSyncProcess.Threads
Console.WriteLine(OpenThread(1, True, ProcessThread.Id))
Next