locked
Deriving a class from Thread RRS feed

  • Question

  • Hi All,

    I need to derive a class from Thread but the System.Threading.Thread is sealed, so it is imposible to derive from ...

    Is there another Thread somewhere in the framework that is not sealed or are other options possible ?

    Thanks for helping !

    Geert
    Friday, November 23, 2007 8:52 AM

Answers

  •  Geert Masureel wrote:

    I need to derive a class from Thread

    Why?


     Geert Masureel wrote:

    Is there another Thread somewhere in the framework that is not sealed

     

    No

     

     Geert Masureel wrote:

    or are other options possible ?

     

    Depends on what you're trying to do. If you just want to store some extra state for the thread there are certainly options.

     

    Friday, November 23, 2007 10:11 AM

All replies

  •  Geert Masureel wrote:

    I need to derive a class from Thread

    Why?


     Geert Masureel wrote:

    Is there another Thread somewhere in the framework that is not sealed

     

    No

     

     Geert Masureel wrote:

    or are other options possible ?

     

    Depends on what you're trying to do. If you just want to store some extra state for the thread there are certainly options.

     

    Friday, November 23, 2007 10:11 AM
  • Perhaps you should use composition instead of inheritance in your class hierarchy? I too cannot think any situation where you need to derive from Thread class.
    Friday, November 23, 2007 11:23 AM
  • Hi guys,

    I'm a (ex) Delphian porting my Delphi framework to C#. One of the components is TabThread, a derived class from TThread and it contains things like errorhandling, raising messagebox/inputbox requests to upper classes in a structured uniform way. The graphical layer (Form or console) needs to take care of the final handling of these. It are the same things I use in my TabObject (a derived class from object) and is perfectly working in Delphi. To standardize things it would be nice if I could add an extra parameter in the constructor holding a reference to an abObject and writing some events/methods in the Thread class (synchronising the events). That way users of both the abObject and the abThread find the same extra features and do not have to take care of these. Write once, use many ... ... the usual reason for deriving classes.

    I must admitt that I have not used Threads in C# so far (will soon), but I have used a lot of them in Delphi. Maybe I should have a closer look at how Threads work in C# first but I expect it will be similar to Delphi threads.

    Mattias, if you could give some info on the extra states, I would really appreciate it !

    Rauhanlinnake, thanks for the tip on composing, I will have a closer look at that as well over the weekend.

    Thanks for helping !

    Geert
    Friday, November 23, 2007 12:48 PM