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