Solved

vb.net - convert from C# to VB

Posted on 2010-08-30
6
735 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 74

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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
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.

757 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

19 Experts available now in Live!

Get 1:1 Help Now