Asmod Posted January 27, 2004 Posted January 27, 2004 Just started playing with C# after many years of Delphi coding. One question I have is to do with Class inheritance. In Delphi you could do things like this TMyClass = Class(TThread) .... Public FVariable : string; End; MyClass : TMyClass; MyClass := TMyClass.Create(True); MyClass.FVariable := 'Test'; but as I found in C# there seems to be no way of inheriting a thread due to the fact the class is sealed. I'm guessing I'm just being narrow minded and my past Delphi experience is making this harder than is needs to be. Am I overlooking something simple here or can it just not be done? I would like to create a class that is basically a thread but with a couple of extra variables and functions in it. Thanks for any help! Quote
NK2000 Posted January 27, 2004 Posted January 27, 2004 you cant inherit sealed classes that is true but i ask why do you have to inherit a Thread? You can point to any method since it uses delegates..so there should be no need, if you got a problem to realize something just post it and we will look together for a solution, ok? :) Quote
Asmod Posted January 27, 2004 Author Posted January 27, 2004 Only wanted to inherit a thread so I could create thread specific variables and procedures. If I have a program that reads data from a huge array I'd like to pass off jobs to a thread along with an 'id' number which would reference part of the array and maybe some other information too. Its the passing variables/parameters to a thread that I can't work out. I thought maybe you'd have to create your own class and inherit a thread but that appears impossible so there must be some way to pass this info over! Thanks Quote
NK2000 Posted January 27, 2004 Posted January 27, 2004 uhm normally a thread just opens something like a "2nd process" so like a second application you can work at the same time on more than one thing, normally you pass the arguments to the object of the method where the threadstart delegate aims to Quote
Optikal Posted January 28, 2004 Posted January 28, 2004 You can pass data to a new thread by setting instance members of the object which contains the instance method which you use to launch the thread. A full explanation and example can be found here: http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcreatingthreads.asp Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.