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!
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: