I would like to be able to name a BackgroundWorker to make it easier to debug. Is this possible?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’d have to try but can’t you just set the Name of the thread in the DoWork() method executed by the BackgroundWorker?
UPDATE: I just tried the following line of code as the first statement of my BackgroundWorkers DoWork() method and it works:
UPDATE: As Jonathan Allen correctly stated the name of a thread is write once, so I added a null check before setting the name. An attempt to write the name for the second time would result in an InvalidOperationException. As Marc Gravell wrote it might also make debugging harder as soon as pooled background threads are re-used for other work, so name threads only if necessary..