I created a instance of this class and I've noticed that the internal Thread keeps running after the class instance goes out of scope.
Yes, mainly for two reasons.
1. A thread doesn't die just because there is no reference to it's class. It's referencing the class itself, so it's not going to be garbage collected.
2. Nothing happens to the object when the variable referencing it goes out of scope. Absolutely nothing. When an object becomes unreachable it's up for garbage collection, but the garbage collector doesn't care about scope at all, only usage. The concept of scope is only relevant to the compiler.
I can see that the only way to stop the Thread is to implement a "public Teminate()" method that kills the Thread.
The well behaved way of stopping a thread is to tell it to stop, and let it exit out of it's main method by itself. Changing the value of a volatile variable that the thread is polling, is one way of doint that.
I wanted to implicity shut down the internal Thread so I tried to implement Finalizer. this didnt work for me - the Internal thread kept running and the Finalizer never called
Of course not, the Finalizer is only called once the garbage collector notices that the object is up for garbage collection, but as the thread is referencing the object, it never will be.
If you want to control the life cycle of an object, you should implement the IDisposable interface.
Despite everything, the person most likely to be fooling you next is yourself.
i have a question about object oriented(class inheritance)
i have a windows application with c# that in this application i have 2 forms. these 2 forms have few methods i show you below.
public partial class form1:Form
public void change_value_label(string new_value)
lbl.Text=new_value;//this label defined as private controll for this form
public partial class form2:Form
private void subject_Load(object sender, EventArgs e)
//in this area code i want to write a code that call change_value_label method of form1 , but i can't
// if i create a new object of form1 then i can call the method but with this way i cannot change the value of the label on form1
//and if i declare change_value_label method on form1 as static method then on the method i cannot access to the label because this controll is not static and i //cannot define the label as static control
//please tell me what do i have to do to solve this problem?
form1 and form2 are showing at te same time because this two forms are children forms.
nobody help you...
you have to help you yourself
and this is success way.
Only you can choose the one that is the best for you. This is a highly subjective issue, and it's up to you to look at it based on the criteria that you think is important - for instance, is ease of use important to you, or support for the latest versions of the PDF format, or speed of PDF creation? Only you can decide which meets your criteria.
Deja View - the feeling that you've seen this post before.
Thanks for the reply. I need one that is compatible with .NET 2.0. Ease of use is important, but so is speed. Basically, one that can accommodate most of what you mentioned. Perhaps, one that people have used and have good things to say about.
I had written service which will fire for every 3 seconds.Actually I had written a service which fire when an user open a word document and click print button on it.For this Iam using WMI from that Iam checking jobs for every 3 sec.
Now I want to make my service work only when a print button(i.e., normal print option from notepad,wordpad,document....like..)is fired.
I think i have to watch the events.....how to do that i have no idea..
Kindly help me and guide in proper way..
Last Visit: 31-Dec-99 19:00 Last Update: 27-Feb-21 13:05