开发者

Suspend/resume thread?

开发者 https://www.devze.com 2023-04-01 23:37 出处:网络
Is it possible in VB.NET to suspend and resume pro开发者_开发技巧cesses? I would like to entirely pause a process or an external thread.Warning: .Suspend() has been depreciated. The reason is suspend

Is it possible in VB.NET to suspend and resume pro开发者_开发技巧cesses?

I would like to entirely pause a process or an external thread.


Warning: .Suspend() has been depreciated. The reason is suspending another thread is not even remotely safe.

Lets say somewhere on a lower level, there is a thread performing some important operation like writing bytes, now you go ahead and suspend the thread before it finishes what happens to that range of bytes? It will likely be paused until you Resume() which can lead to damaging results.

with that said:

Thread.Sleep(Time in ms) 

will pause the current thread for x amount of milliseconds.

If you are looking to Suspend the current thread then

Thread.CurrentThread.Suspend()

and to resume the current thread

Thread.CurrentThread.Resume()

You will need to import the namespace to use this code as is.

Imports System.Threading

or change it to

System.Threading.Thread.CurrentThread.Suspend()

Be careful and if your not Multi-Threading and handling your own threads, I don't recommend it. There is a reason why MS depreciated the code. Keep that in mind.


This is the right way to do what (I think) you need.
You have to call ResumeThread() and SuspendThread() (API functions) on all the threads of target process...

0

精彩评论

暂无评论...
验证码 换一张
取 消