GlobaLevel
asked on
vb.net - convert from C# to VB
I am getting a few errors on my conversion from C#.NET to VB.NET...can anyone help..thanks....
Errors like:
Delegate 'System.Threading.Threadst art' 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(Ne w System.Threading.ThreadSta rt(WorkerT ))
Dim ContinueWorking As Boolean
' workerthread = "NULL"
Public Sub onStart()
ContinueWorking = True
workerthread = New System.Threading.Thread(Ne w System.Threading.ThreadSta rt(WorkerT ))
workerthread.Start()
this.EventLog.WriteEntry(" event message text", EventLogEntryType.Informat ion)
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.ThreadSta te.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.CreateN ew, System.IO.FileAccess.ReadW rite, System.IO.FileShare.None, 2048)
fs = new System.IO.FileStream(@"c:\ " + fFileName + ".txt", System.IO.FileMode.CreateN ew, System.IO.FileAccess.ReadW rite, System.IO.FileShare.None, 2048)
fs.Write(new byte[] { 1, 2, 3, 4, 5 }, 0, 5)
fs.Flush()
fs.Close()
System.Threading.Thread.Sl eep(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.CreateN ew, System.IO.FileAccess.ReadW rite, 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
Errors like:
Delegate 'System.Threading.Threadst
'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(Ne
Dim ContinueWorking As Boolean
' workerthread = "NULL"
Public Sub onStart()
ContinueWorking = True
workerthread = New System.Threading.Thread(Ne
workerthread.Start()
this.EventLog.WriteEntry("
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.ThreadSta
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:\
fs = new System.IO.FileStream(@"c:\
fs.Write(new byte[] { 1, 2, 3, 4, 5 }, 0, 5)
fs.Flush()
fs.Close()
System.Threading.Thread.Sl
Dim fexit As String
Dim fe As New System.IO.FileStream
fexit = Guid.NewGuid().ToString()
fe = new System.IO.FileStream(@"c:\
fe.Write(new byte[] { 1, 2, 3, 4, 5 }, 0, 5)
fe.Flush()
fe.Close()
End While
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Pretty sure you don't even need the ThreadStart in VB...
...think you can just do:
Dim workerthread As New System.Threading.Thread(Ad dressOf WorkerT)
...think you can just do:
Dim workerthread As New System.Threading.Thread(Ad
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/
http://www.developerfusion.com/tools/convert/csharp-to-vb/
workerthread = New System.Threading.Thread(Ne
to this line
workerthread = New System.Threading.Thread(Ne