Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!

Posted
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? :)
Posted

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

Posted
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...