I am trying to convert a VB.NET project to C#. I am conveting all the forms and classes as required, but I don't know where I need to write the events from ApplicationEvents.vb (I believe its autoGenerated from Properties)
Here is the code in my ApplicationEvent.vb file:
Imports GM.Powertrain.RemoteCopy.Interfaces
Imports System.Runtime.Remoting.Channels.Tcp
Imports System.Runtime.Remoting.Channels
Namespace My
Partial Friend Class MyApplication
Private Shared serviceConfig As ServiceConfig =
serviceConfig.Load()
Protected Overrides Function OnStartup(
ByVal eventArgs As StartupEventArgs) As Boolean
Dim channel As TcpChannel = New TcpChannel()
ChannelServices.RegisterChannel(channel, False)
Me.MainForm = New Computer_Network_MAIN_SCREEN()
Return MyBase.OnStartup(eventArgs)
End Function
Public ReadOnly Property Config() As ServiceConfig
Get
Return serviceConfig
End Get
End Property
Public ReadOnly Property LocalMachine() As IRemoteCopier
Get
Return serviceConfig.GetObject(Of IRemoteCopier)("localhost")
End Get
End Property
End Class
End Namespace
Also, any tips that may help on this conversion would be appreciated. Thanks!
Here is a way to find your answer by yourself for this kind of question:
Here is some links to .Net decompiler
http://www.telerik.com/products/decompiler.aspx
http://www.jetbrains.com/decompiler/
http://www.devextras.com/decompiler/
http://wiki.sharpdevelop.net/ilspy.ashx
or maybe you'll be able to find an old version of .Net Reflector when it was free...
How to convert this class depends entirely on how you have implemented the new C# project.
If this is a standard windows forms project, I would add the OnStartup code to
Main
just before the main form is opened. Of this code, you probably only need the serviceConfig and Channel-related items, not the MainForm code.Visual Studio 2010 creates Program.cs file for C# application projects.
Application.Run() would, if this was VB.NET, fire "Startup" event. In this case, you don't need to catch that event because you control when is the application going to run using the code specified above.
If you want to subscribe to the event fired when the application is about to close, use this code:
and then define the function to handle this event:
As a result, your code should look something like this:
There is no equivalent file for ApplicationEvent.vb in c#. But you can write whatever code is there in OnStartup function before you start the loop in Program.cs.
Hope this helps.