Randy,
Unfortunately, this is not possible. The BackgroundWorker class uses a
thread from the thread pool (through a call to BeginInvoke on a delegate) to
handle the background task (which upon thinking about it, is a really bad
idea, since the background task might take a very long time to complete).
Because of this, you don't have a reference to a Thread object which you can
set the name on.
The only thing I can think of doing which would accomplish this would be
to set the name of the thread (using the static CurrentThread property) in
the callback for the BackgroundWorker, and setting the name of that thread
there.
However, this can cause an issue, because another piece of code can set
the name of the thread before you do, and that would cause an error. While
the Name property of the Thread is supposed to be write-once, it appears
that you can pass null to the Name property and it will take (I'm not sure,
you have to check). If it allows you to do that, then you can set it to
null, then set it to your name, and then set it to null again when the
background thread completes.
Of course, this is completely implementation-dependent, and I would not
recommend doing this, but it seems like it might be able to do be done.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
(E-Mail Removed)
"randy1200" <(E-Mail Removed)> wrote in message
news:385C7000-153B-427F-B35C-(E-Mail Removed)...
>I have an application with several BackgroundWorker threads. I hoped I'd be
> able to just type backgroundworker1.Name = "bw1"; but I don't see a name
> property.
>
> Any thoughts on how to name a backgroundworker thread?
>
> Thanks,
> Randy