473,387 Members | 1,516 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,387 software developers and data experts.

Calling Shared Constructors/Finalizers

Is there a way to explicitly call a shared constructor or shared
finalizer in a static class?

Jan 22 '07 #1
5 1171

Xe******@gmail.com wrote:
Is there a way to explicitly call a shared constructor or shared
finalizer in a static class?
I'm not sure I even understand why it would be necessary... can you
explain a little more please?

Jan 22 '07 #2
Xe******@gmail.com wrote:
Is there a way to explicitly call a shared constructor or shared
finalizer in a static class?
Hi,

No, there is not. Also, shared (static) finalizers do not exist. Can
you explain a bit more about what you're trying to accomplish?

Brian

Jan 22 '07 #3
Hi,

The original poster and I work together. I've read (i.e.
http://www.csharpfriends.com/Article...?articleID=116)
that it is possible. But we could't find how to actually do it.

We need to restart our application. So instead of quitting and
re-executing it, we thought we could programatically invoke the class
constructors to re-initialize everything.

Paul
Brian Gideon wrote:
Xe******@gmail.com wrote:
Is there a way to explicitly call a shared constructor or shared
finalizer in a static class?

Hi,

No, there is not. Also, shared (static) finalizers do not exist. Can
you explain a bit more about what you're trying to accomplish?

Brian
Jan 23 '07 #4

ti***************@hotmail.com wrote:
Hi,

The original poster and I work together. I've read (i.e.
http://www.csharpfriends.com/Article...?articleID=116)
that it is possible. But we could't find how to actually do it.

We need to restart our application. So instead of quitting and
re-executing it, we thought we could programatically invoke the class
constructors to re-initialize everything.

Paul

Paul,

My guess is that the article is referring to the possibility of calling
the type initializer via reflection. I'm not sure I would use the word
explicit to describe it though.

Module Module1

Sub Main()
Dim t As Type = GetType(Test)
t.TypeInitializer.Invoke(Nothing, Nothing)
End Sub

End Module

Public Class Test

Shared Sub New()
Console.WriteLine("It worked!")
End Sub

End Class

Note that "It worked!" is printed twice. Also, this a pretty flagrant
hack. I recommend considering a different approach to reinitializes
the application's state.

Brian

Jan 23 '07 #5
Thanks a lot Brian.

I know doing this is definitely not elegant. However, I'm not sure what
could go wrong?
Paul

Brian Gideon wrote:
ti***************@hotmail.com wrote:
Hi,

The original poster and I work together. I've read (i.e.
http://www.csharpfriends.com/Article...?articleID=116)
that it is possible. But we could't find how to actually do it.

We need to restart our application. So instead of quitting and
re-executing it, we thought we could programatically invoke the class
constructors to re-initialize everything.

Paul


Paul,

My guess is that the article is referring to the possibility of calling
the type initializer via reflection. I'm not sure I would use the word
explicit to describe it though.

Module Module1

Sub Main()
Dim t As Type = GetType(Test)
t.TypeInitializer.Invoke(Nothing, Nothing)
End Sub

End Module

Public Class Test

Shared Sub New()
Console.WriteLine("It worked!")
End Sub

End Class

Note that "It worked!" is printed twice. Also, this a pretty flagrant
hack. I recommend considering a different approach to reinitializes
the application's state.

Brian
Jan 23 '07 #6

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

Similar topics

6
by: Dolphin White | last post by:
For example, I allocate some unmanaged resources in the static constructors, then how can I properly release the resource before the application exit? thx!
4
by: Claire | last post by:
I'm having real brain failure today. I've done this lots of times with constructors but not with virtual methods and the compiler complains because Ive put the :base(foo) after the function...
33
by: Joe Fallon | last post by:
1. I have a Base class that has a certain amount of functionality. 2. Then I have a CodeSmith generated class that inherits from the Base class and adds functionality. 3. Since I want to be able...
5
by: ElanKathir | last post by:
Hi All ! I want to know about the constructors & Destructors, constructors ---> New Destructors --> What ? (Which keyword to use for Destructor) Thanks & Regards, ElanKathir.S.N, ASM...
12
by: Joe Narissi | last post by:
I know how to create and use static constructors, but is there a such thing as a static destructor? If not, then how do you deallocate memory intialized in the static constructor? Thanks in...
9
by: Peter Oliphant | last post by:
I've been told that value structs can have default constructors (I'm using VS C++.NET 2005 PRO using clr:/pure syntax). But the following code generates the following error: value struct...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
7
by: Jeremy Chaney | last post by:
I have an application written in C# that uses objects written in a managed C++ DLL. When I exit my app, my C# classes have their destructors called, but the MC++ objects that those classes hold...
1
by: timexsinclair2068 | last post by:
Hi, I'm getting some exceptions when creating new threads. That might -or might not- have to do with a probable (?) re-execution of shared constructors. Is that possible? Do shared constructors...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
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
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...
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.