473,796 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2974

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 "KeepRunnin g" on the class
with the thread and within your main thread loop you do

while(KeepRunni ng) {
...
}

and then in the Close event you set singleton.KeepR unning = 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
21096
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 the MSDN example). But is it possible that we just implement the Dispose method, which we will call at the end of the application? Will there be any memory leak or side effects?
4
1935
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 release refrence from memory ? E. If it release object from memory then what GC does ? 2. Which class can have dispose method ? class which is member of IDispose Inteface 3. Where we should use abstract / Interface ?
11
5313
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 4-month old C#/MC++ .NET project project. I'd like to thank in advance anyone who takes the time to read and/or respond to this message. At a couple points, it may seem like a rant against C# / .NET, but we are pretty firmly stuck with this approach...
14
1894
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 call in every method of my classes, would it be a workable way to implement IDisposable in the base class to all the BLL-classes and then in the Dispose method to do the audit call? Do I then have to make sure that all uses of the BLL-classes end...
156
5908
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 inside a method call. dim myvar as new object1 object1.dosomethingmethod(new object2) Note that object 2 has a dispose method but how do I dispose of it unless I do the following:
6
3587
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. what is the correct way of implementing IDisposable.Dispose? 3. what is the preferred way, if there is one over the other, of calling the Dispose method on an object that implements IDisposable. Is it the way that uses the "using(object){}" construct...
71
10763
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 is that automatic? Thanks
4
2033
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
9135
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 it's enough to pay attention when disposing objects of type A from "consumer" classes? Thanks, Luigi.
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10456
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10012
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7548
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.