如何在托管C ++代码中停止线程 [英] How to stop Thread in Managed C++ Code

查看:68
本文介绍了如何在托管C ++代码中停止线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经管理了使用Thread的C ++代码.
我已经开始像下面的线程

Hi,

I have managed C++ code in which i am using Thread.
I have started Thread like below

ThreadStart* threadStart = new ThreadStart(pThread, CThread::MyFile);
Thread* oThread = new Thread(threadstart);
oThread->Start();



一旦我要求的工作完成.我必须停止线程.我该怎么办?
确实需要停止线程吗?我以为一旦完成我要求的工作,线程就会自动停止.

有什么建议吗?

问候,
AJ83



Once my requested job done. I have to stop thread. How can i do this?
Is it really required to stop the thread? I was assuming that once my requested job will done, Thread will automatically stop itself.

Any suggestion?

Regards,
AJ83

推荐答案

请参阅我对问题的评论.当您说一旦完成我请求的工作",您就不需要做任何事情.
线程将退出方法threadstart并将其停止.

至于对象oThread,在对象变得无法到达之后,它将最终被GC破坏.

—SA
Please see my comments to the question. As you say "once my requested job is done", you don''t need to do anything.
The thread will exit the method threadstart and it will stop it.

As to the object oThread, it will be destroyed by GC eventually, after the object becomes unreacheable.

—SA


这篇关于如何在托管C ++代码中停止线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆