Solved

vb.net - convert from C# to VB

Posted on 2010-08-30
6
764 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 86

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

749 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