Solved - convert from C# to VB

Posted on 2010-08-30
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'


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))
        this.EventLog.WriteEntry("event message text", EventLogEntryType.Information)
    End Sub

    Public Sub onStop()

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

        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)

            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)
        End While
    End Sub

End Class

Question by:GlobaLevel
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))
LVL 11

Accepted Solution

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)
 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)
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)
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

LVL 17

Expert Comment

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:

LVL 29

Expert Comment

by:Kumaraswamy R
ID: 33564237
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 33574584
Check the link

Hope this will you

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now