Solved

vb.net - convert from C# to VB

Posted on 2010-08-30
6
744 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

943 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

8 Experts available now in Live!

Get 1:1 Help Now