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

Translating VB to C#

134 100+
Can anyone help me to translate this to C# please?

Any help would be appreciated.

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3.     Delegate Sub SetCloseCallback(ByVal closeform)
  4.     Private Sub SetClose(ByVal closeform)
  5.  
  6.         If Me.InvokeRequired Then
  7.             Dim d As New SetCloseCallback(AddressOf SetClose)
  8.             Me.Invoke(d, New Object() {closeform})
  9.         Else
  10.             Me.Close()
  11.         End If
  12.  
  13.     End Sub
  14.  
  15.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  16.         'Start the worker to perform the operation
  17.         worker.RunWorkerAsync()
  18.     End Sub
  19.  
  20.     Private Sub worker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles worker.DoWork
  21.  
  22.         Dim wc As New WebClient()
  23.         Dim blah As Object = Nothing
  24.         Dim p As Process
  25.         Dim app As String = GetSetting("ACv2022", "Main", "AppName")
  26.  
  27.         If app = "" Then app = "EvoSoft AC v2.exe"
  28.  
  29.         For Each p In Process.GetProcesses
  30.             If p.MainWindowTitle.Equals("EvoSoft Anti-cheat") Then
  31.                 p.Kill()
  32.             End If
  33.         Next
  34.  
  35.         'Waiting for the client to close
  36.         Thread.Sleep(1000)
  37.  
  38.         Try
  39.             'Remove old client
  40.             If File.Exists(Environment.CurrentDirectory & "\" & app) Then
  41.                 File.Delete(Environment.CurrentDirectory & "\" & app)
  42.             End If
  43.  
  44.             'Download new client
  45.             wc.DownloadFile("http://www.evosoft-acp.com/updater/client.exe", Environment.CurrentDirectory & "\" & app)
  46.  
  47.             Process.Start(Environment.CurrentDirectory & "\" & app)
  48.  
  49.         Catch ex As Exception
  50.  
  51.             MessageBox.Show("An unknown error occured, please update the EvoSoft client manually.")
  52.             SetClose(blah)
  53.  
  54.         End Try
  55.  
  56.         SetClose(blah)
  57.  
  58.     End Sub
  59.  
  60. End Class
  61.  
Apr 11 '12 #1

✓ answered by Frinavale

Check out this free online tool: Convert C# to VB.NET & vice versa. It doesn't always work 100% but it's pretty good and you just have to do a bit of cleanup (for things like addhandler or lambda expressions).

It produced the following
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Diagnostics;
  6. public class Form1
  7. {
  8.  
  9.     public delegate void SetCloseCallback(closeform);
  10.     private void SetClose(closeform)
  11.     {
  12.  
  13.         if (this.InvokeRequired) {
  14.             SetCloseCallback d = new SetCloseCallback(SetClose);
  15.             this.Invoke(d, new object[] { closeform });
  16.         } else {
  17.             this.Close();
  18.         }
  19.  
  20.     }
  21.  
  22.     private void Form1_Load(System.Object sender, System.EventArgs e)
  23.     {
  24.         //Start the worker to perform the operation
  25.         worker.RunWorkerAsync();
  26.     }
  27.  
  28.     private void worker_DoWork(System.Object sender, System.ComponentModel.DoWorkEventArgs e)
  29.     {
  30.  
  31.         WebClient wc = new WebClient();
  32.         object blah = null;
  33.         Process p = null;
  34.         string app = Interaction.GetSetting("ACv2022", "Main", "AppName");
  35.  
  36.         if (string.IsNullOrEmpty(app))
  37.             app = "EvoSoft AC v2.exe";
  38.  
  39.         foreach (Process p_loopVariable in Process.GetProcesses()) {
  40.             p = p_loopVariable;
  41.             if (p.MainWindowTitle.Equals("EvoSoft Anti-cheat")) {
  42.                 p.Kill();
  43.             }
  44.         }
  45.  
  46.         //Waiting for the client to close
  47.         Thread.Sleep(1000);
  48.  
  49.         try {
  50.             //Remove old client
  51.             if (File.Exists(Environment.CurrentDirectory + "\\" + app)) {
  52.                 File.Delete(Environment.CurrentDirectory + "\\" + app);
  53.             }
  54.  
  55.             //Download new client
  56.             wc.DownloadFile("http://www.evosoft-acp.com/updater/client.exe", Environment.CurrentDirectory + "\\" + app);
  57.  
  58.             Process.Start(Environment.CurrentDirectory + "\\" + app);
  59.  
  60.         } catch (Exception ex) {
  61.  
  62.             MessageBox.Show("An unknown error occured, please update the EvoSoft client manually.");
  63.             SetClose(blah);
  64.  
  65.         }
  66.  
  67.         SetClose(blah);
  68.  
  69.     }
  70.     public Form1()
  71.     {
  72.         Load += Form1_Load;
  73.     }
  74.  
  75. }


-Frinny

2 2218
Frinavale
9,735 Expert Mod 8TB
Check out this free online tool: Convert C# to VB.NET & vice versa. It doesn't always work 100% but it's pretty good and you just have to do a bit of cleanup (for things like addhandler or lambda expressions).

It produced the following
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Diagnostics;
  6. public class Form1
  7. {
  8.  
  9.     public delegate void SetCloseCallback(closeform);
  10.     private void SetClose(closeform)
  11.     {
  12.  
  13.         if (this.InvokeRequired) {
  14.             SetCloseCallback d = new SetCloseCallback(SetClose);
  15.             this.Invoke(d, new object[] { closeform });
  16.         } else {
  17.             this.Close();
  18.         }
  19.  
  20.     }
  21.  
  22.     private void Form1_Load(System.Object sender, System.EventArgs e)
  23.     {
  24.         //Start the worker to perform the operation
  25.         worker.RunWorkerAsync();
  26.     }
  27.  
  28.     private void worker_DoWork(System.Object sender, System.ComponentModel.DoWorkEventArgs e)
  29.     {
  30.  
  31.         WebClient wc = new WebClient();
  32.         object blah = null;
  33.         Process p = null;
  34.         string app = Interaction.GetSetting("ACv2022", "Main", "AppName");
  35.  
  36.         if (string.IsNullOrEmpty(app))
  37.             app = "EvoSoft AC v2.exe";
  38.  
  39.         foreach (Process p_loopVariable in Process.GetProcesses()) {
  40.             p = p_loopVariable;
  41.             if (p.MainWindowTitle.Equals("EvoSoft Anti-cheat")) {
  42.                 p.Kill();
  43.             }
  44.         }
  45.  
  46.         //Waiting for the client to close
  47.         Thread.Sleep(1000);
  48.  
  49.         try {
  50.             //Remove old client
  51.             if (File.Exists(Environment.CurrentDirectory + "\\" + app)) {
  52.                 File.Delete(Environment.CurrentDirectory + "\\" + app);
  53.             }
  54.  
  55.             //Download new client
  56.             wc.DownloadFile("http://www.evosoft-acp.com/updater/client.exe", Environment.CurrentDirectory + "\\" + app);
  57.  
  58.             Process.Start(Environment.CurrentDirectory + "\\" + app);
  59.  
  60.         } catch (Exception ex) {
  61.  
  62.             MessageBox.Show("An unknown error occured, please update the EvoSoft client manually.");
  63.             SetClose(blah);
  64.  
  65.         }
  66.  
  67.         SetClose(blah);
  68.  
  69.     }
  70.     public Form1()
  71.     {
  72.         Load += Form1_Load;
  73.     }
  74.  
  75. }


-Frinny
Apr 11 '12 #2
michaeldebruin
134 100+
oke thanks for all the help Frinavale
Apr 12 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Numberwhun | last post by:
Hello everyone! I am trying to learn java and have run into kind of a snag. Here is the code that I have so far: ------ <begin_code> ---------- import javax.swing.*; import...
1
by: Huang Lin | last post by:
I want to query tables in different Database,such as Oracle,Db2,Sql Server£¬ etc.Give me some ideals,Please!
18
by: free2cric | last post by:
Hi, I attanded an interview on C++ Question asked were and my answers to them.. 1. In a CPP program what does memory leak occure? -- i said.. In a constructor , the pointer variables were...
11
by: Lues | last post by:
Hi, I'm trying to protect some data in tables with encription (you know why, don't you ;)) I must confess that I'm not very expirienced in writing code, especially encription code. Can any...
1
by: albert_reade | last post by:
Hello I was wondering if someone could please help me understand what I need to do in order to get this project to work. I just need some hints or a push in the right direction to get this to work,...
11
by: shapper | last post by:
Hello, I am creating a centered web site with various div's inside the main (pBase) div. Somehow, I am getting a gap on the top of my browser window both in IE and Firefox. I tried...
1
by: =?Utf-8?B?RW1tYSBIb3Bl?= | last post by:
Hi All, I need some advice please. I have very good knowledge of MS Access, Excel etc, reasonable knowledge of VBA and some very basic knowledge of VB6 and virtually non-existant knowledge of...
2
by: karafire2003 | last post by:
I've been tasked to do 2 questions. I think i got the majority of it done, but i'm having trouble. Question #1: Write a C program that accepts as input from the keyboard a floating point number, an...
3
by: swanside | last post by:
Hello all. I am in the need of some help please. I have an SQL statement that works on a MySQL Database, but I need to get it to work on an Access Database. The statement is, SELECT...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.