473,327 Members | 2,094 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,327 software developers and data experts.

How use instance's fields immediatelly before they are destroyed

Hi friends, that's my question. I need use the instance's fields in my
last process before they are destroyed. Similar to a C++ destructor, because
C# destructor is called after of destroy the fields.

Thx in advance,

Naldo Alcalde H.
Nov 17 '05 #1
6 1154
Naldo Alcalde <li*************@hotmail.com> wrote:
Hi friends, that's my question. I need use the instance's fields in my
last process before they are destroyed. Similar to a C++ destructor, because
C# destructor is called after of destroy the fields.


No, the C# finalizer is called at some point which may be before or
after the finalizer is called on the objects referred to by the fields.
There's no guarantee that it will be afterwards (and indeed there can't
be - there could be cyclic references).

Having to use a finalizer at all is usually a sign of a design which
needs rethinking though - what exactly are you trying to do?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
Hi, Jon, thx for you answer. I'm implementing a Log class that writes
the initial message for example

"*** Log Started at yyyy-MMM-dd hh:mm:ss.fff ***"

and want the similar for the last message

"*** Log Stopped at yyyy-MMM-dd hh:mm:ss.fff ***"

for that reason I want write this message as last processing.

Best regards,

Naldo Alcalde H.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Naldo Alcalde <li*************@hotmail.com> wrote:
Hi friends, that's my question. I need use the instance's fields in my last process before they are destroyed. Similar to a C++ destructor, because C# destructor is called after of destroy the fields.


No, the C# finalizer is called at some point which may be before or
after the finalizer is called on the objects referred to by the fields.
There's no guarantee that it will be afterwards (and indeed there can't
be - there could be cyclic references).

Having to use a finalizer at all is usually a sign of a design which
needs rethinking though - what exactly are you trying to do?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #3
Naldo Alcalde <li*************@hotmail.com> wrote:
Hi, Jon, thx for you answer. I'm implementing a Log class that writes
the initial message for example

"*** Log Started at yyyy-MMM-dd hh:mm:ss.fff ***"

and want the similar for the last message

"*** Log Stopped at yyyy-MMM-dd hh:mm:ss.fff ***"

for that reason I want write this message as last processing.


Is the idea that you only want to stop when the application finishes?
If so, you could possibly use the AppDomain.DomainUnload or
AppDomain.ProcessExit events.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
Yep, the stop message must be written when the application finishes.

Use the events that you have mentioned will be useful if my log
instances has
global scope, but that not always is the case.

I think that the instances itself must have some way to do this.

Naldo Alcalde H.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Naldo Alcalde <li*************@hotmail.com> wrote:
Hi, Jon, thx for you answer. I'm implementing a Log class that writes the initial message for example

"*** Log Started at yyyy-MMM-dd hh:mm:ss.fff ***"

and want the similar for the last message

"*** Log Stopped at yyyy-MMM-dd hh:mm:ss.fff ***"

for that reason I want write this message as last processing.


Is the idea that you only want to stop when the application finishes?
If so, you could possibly use the AppDomain.DomainUnload or
AppDomain.ProcessExit events.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #5
Naldo Alcalde <li*************@hotmail.com> wrote:
Yep, the stop message must be written when the application finishes.

Use the events that you have mentioned will be useful if my log
instances has global scope, but that not always is the case.

I think that the instances itself must have some way to do this.


Well, the best way would be to shut the application down cleanly,
telling each object which cares about the lifetime that it's about to
shutdown. Relying on a finalizer isn't a nice way of doing this.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6
Thx a lot Jon for your help.

Naldo Alcalde H.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Naldo Alcalde <li*************@hotmail.com> wrote:
Yep, the stop message must be written when the application finishes.

Use the events that you have mentioned will be useful if my log
instances has global scope, but that not always is the case.

I think that the instances itself must have some way to do this.


Well, the best way would be to shut the application down cleanly,
telling each object which cares about the lifetime that it's about to
shutdown. Relying on a finalizer isn't a nice way of doing this.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #7

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

Similar topics

18
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I...
3
by: John C | last post by:
Hi, I am a little uncertain about the concept of passing a reference to a class to another instance of a class. for instance I thought that the following was ok: Network network = Network();...
3
by: WG | last post by:
Here is an ASP code sample in VBScript: <% Dim x Set x = server.CreateObject("ADODB.RECORDSET") x.CursorType = 1 x.CursorLocation = 3 x.Fields.Append "custtype", adVarNumeric, 80,...
7
by: taylor.bryant | last post by:
I am running: Win XP SP2 Excel 2002, Access 2002 (Office XP SP3) Using Visual Basic (not VB.NET) At one point (prior to XP SP2?!? - I can't pin it down), this did not happen and I was easily...
4
by: Shawn | last post by:
How to prevent my app from being instanced more than once
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
6
by: thomson | last post by:
Hi All, In a Singleton pattern , if we create an instance variable, and return it, whether this one also be a static variable , Can anyone give me insights on the Memory allocation Thanks in...
22
by: WXS | last post by:
Sometimes a method in a class requires the use of class instance variables/fields that will not be used outside of the method itself. Currently this means you must create a instance field in the...
12
by: Analizer1 | last post by:
Hi.... when i use the new keyword myobject obj1 = new myobject() myobject obj2 = new myobject() myobject obj3 = new myobject() does each of the object have a complete instance of myobject,...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.