在由父线程创建的子线程中获取父线程名称 [英] Getting parent thread name in child thread which created by parent thread

查看:282
本文介绍了在由父线程创建的子线程中获取父线程名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试在子线程中获取父线程名称/信息。我想这样做;我的类需要使用父线程信息来连接数据库。我的应用程序运行多线程和每个线程类连接不同的连接字符串。所以当我的父线程创建子线程时,子线程应该使用父线程类连接字符串。



如何在子线程中获取父线程信息?



谢谢,
$ b $bGökhan

解决方案

线程没有名。据我所知,操作系统通常不保留线程之间的父子关系。当然,它们由某个过程托管。换句话说,相同过程的线程在它们的关系中是相等的,没有人知道是另一个的父母或孩子。如果您在创建子线程时实际将一些父线程信息传递给子线程,则只能保留这样的关系。



-SA

Hi,

I''m trying to get parent thread name/info in child thread. I want to do that; My classes need to use parent thread info for connect to database. My application running multithread and each threads classes connecting diffrent connection string. So when my parent threads create sub thread, sub threads should use parent thread classes connection string.

How can take parent thread informations in sub threads?

Thanks,
Gökhan

解决方案

Threads don''t have names. To best of my knowledge, parent-child relationships between threads are not generally preserved by the OS. They are hosted by a certain process, of course. In other words, threads of the same process are equal in their relationships, no one is known to be a parent or a child of another one. You can only preserve some relationships like that, if you actually pass some parent thread information to the child thread when you create them.

—SA


这篇关于在由父线程创建的子线程中获取父线程名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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