473,386 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Dispose, finalize and singleton classes.

Since singleton classes conceptually are like static classes, the are
supposed to last for the entire lifetime of the application.

Starting from this point tell me if I'm wrong saying:
- it make no sense to implement IDisposable
- it make sense to implement Finalize if there are unmanaged resources, else
the GC will not be able to free them
- this is perhaps the only case in which a finalizer is implemented, but a
Dispose is not implemented

If I've a thread in a singleton class, before closing the application I have
to wait for thread end (some way telling the thread it should stop as soon
as possible): could this be done into the Closing or Close event handler of
the main form?
Thanks,
Luigi.
May 21 '07 #1
2 2943

If I've a thread in a singleton class, before closing the application I
have to wait for thread end (some way telling the thread it should stop as
soon as possible): could this be done into the Closing or Close event
handler of the main form?
If the thread.IsAlive, then at the form Close event is where you need to
stop the thread and end the program.

May 21 '07 #2

You could set an instance variable like "KeepRunning" on the class
with the thread and within your main thread loop you do

while(KeepRunning) {
...
}

and then in the Close event you set singleton.KeepRunning = false;

Another option is to set the thread to be a Background thread in which
case it does not have to be shut down manually. You won't get as
clean of an exit from the thread, so which you choose depends entirely
on what the thread actually does.

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Mon, 21 May 2007 11:47:39 +0200, "BLUE" <bluewrote:
>If I've a thread in a singleton class, before closing the application I have
to wait for thread end (some way telling the thread it should stop as soon
as possible): could this be done into the Closing or Close event handler of
the main form?
Thanks,
Luigi.
May 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: celeong | last post by:
Hi, anybody can help me with this. I've created a singleton class, and now wants to add destructor to it. I know we can implement the IDisposable and also overrides the Finalize method (from...
4
by: RiteshDotNet | last post by:
..net Frame work 1. Dispose Method what it does ? A. who its call / when it calls ? B. Is it fire automatically ? c. When dispose method is call what it does ? D. Release a Object from memory or...
11
by: Ken Durden | last post by:
I am in search of a comprehensive methodology of using these two object cleanup approaches to get rid of a number of bugs, unpleasantries, and cleanup-ordering issues we currently have in our...
14
by: Jonas | last post by:
Hi! I'm developing the middletiers of an ASP.NET application in VB.NET. I've got a business logic layer in which I would like to perform auditing to a database. Instead of making an auditing...
156
by: Dennis | last post by:
Ok, I'm trying to dispose of every object that I create that has a dispose method based on advice from this newsgroup. However, I'm not sure how to dispose of the following object that was created...
6
by: Water Cooler v2 | last post by:
I heard from someone that we must not implement IDisposable for all classes. Can someone please tell me: 1. the reason why we must not implement IDisposable for all the classes we write. 2....
71
by: active | last post by:
In the main program I check to see if a certain form has been disposed. Does it make sense in that form's FormClosed event to do: Me.Dispose to make sure it is disposed the next time I check. Or...
4
by: BLUE | last post by:
I've read many articles including the one from Duff's blog but I've many doubts. public static myClass Instance { get { if (myClass.instance == null) myClass.instance = new myClass();
11
by: BLUE | last post by:
I've a class A that implements IDisposable interface and has a method that start a thread. In Dispose(bool) can I use the lock keyword to wait for thread exit before disposing resources it use or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.