Solved

vb.net - convert from C# to VB

Posted on 2010-08-30
6
757 Views
Last Modified: 2012-05-10
I am getting a few errors on my conversion from C#.NET to VB.NET...can anyone help..thanks....

Errors like:

Delegate 'System.Threading.Threadstart' requires an 'AddressOf' expression or lambda expression as  the only argument to its constructor

'Over load resolution failed because no accessible 'Write' accepts this number of arguments'

'Name 'this' is not declared'

'Name 'args' is not declared'

'name base is not declared'


Code:

Imports System.Threading.Thread
Imports System.IO
Imports System.IO.FileStream


Public Class Form1

    Dim workerthread As New System.Threading.Thread(New System.Threading.ThreadStart(WorkerT))
    Dim ContinueWorking As Boolean
    ' workerthread = "NULL"

    Public Sub onStart()

        ContinueWorking = True
        workerthread = New System.Threading.Thread(New System.Threading.ThreadStart(WorkerT))
        workerthread.Start()
        this.EventLog.WriteEntry("event message text", EventLogEntryType.Information)
        base.OnStart(args)
    End Sub

    Public Sub onStop()

        ContinueWorking = False
        ' give the worker 30 seconds to finish, abort after
        workerthread.Join(30000)
        If (workerthread.ThreadState <> System.Threading.ThreadState.Stopped) Then
            workerthread.Abort()

            base.OnStop()
        End If
    End Sub

    Private Sub WorkerT()

        ' go into endless loop, the only way to leave this loop is through a signal
        While (ContinueWorking)

            Dim fFileName As String
            Dim fs As New System.IO.FileStream
            fFileName = "C:\test"
            fFileName = Guid.NewGuid().ToString()

            ' System.IO.FileStream fs = new System.IO.FileStream(@"c:\" + fFileName + ".txt", System.IO.FileMode.CreateNew, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None, 2048)
             fs = new System.IO.FileStream(@"c:\" + fFileName + ".txt", System.IO.FileMode.CreateNew, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None, 2048)
            fs.Write(new byte[] { 1, 2, 3, 4, 5 }, 0, 5)
            fs.Flush()
            fs.Close()
            System.Threading.Thread.Sleep(10000)

            Dim fexit As String
            Dim fe As New System.IO.FileStream
            fexit = Guid.NewGuid().ToString()
            fe = new System.IO.FileStream(@"c:\exit_" + fexit + ".txt", System.IO.FileMode.CreateNew, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None, 2048)
            fe.Write(new byte[] { 1, 2, 3, 4, 5 }, 0, 5)
            fe.Flush()
            fe.Close()
        End While
    End Sub

End Class

0
Comment
Question by:GlobaLevel
6 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 33563146
Change this line

    workerthread = New System.Threading.Thread(New System.Threading.ThreadStart(WorkerT))

to this line

    workerthread = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf WorkerT))
0
 
LVL 11

Accepted Solution

by:
ladarling earned 500 total points
ID: 33563189
Make these changes:
Dim workerthread As New System.Threading.Thread(New System.Threading.ThreadStart(WorkerT))
Dim workerthread As New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf WorkerT))
 
 this.EventLog.WriteEntry("event message text", EventLogEntryType.Information)
 Me.EventLog.WriteEntry("event message text", EventLogEntryType.Information)
base.OnStart(args)
MyBase.OnStart()
 Change ALL occurances of this:
 fs.Write(new byte[] { 1, 2, 3, 4, 5 }, 0, 5)
 fs.Write(new byte() { 1, 2, 3, 4, 5 }, 0, 5)
 
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 33563722
Pretty sure you don't even need the ThreadStart in VB...

...think you can just do:

    Dim workerthread As New System.Threading.Thread(AddressOf WorkerT)
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 17

Expert Comment

by:Zhaolai
ID: 33563753
The following web site converts C# code to VB.NET for free. It does a pretty good job. I used it a lot of times:

http://www.developerfusion.com/tools/convert/csharp-to-vb/

0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 33564237
0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 33574584
Check the link
http://www.tangiblesoftwaresolutions.com/index.htm

Hope this will you
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question