Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. problem with thread program converting from c# to vb.net

problem with thread program converting from c# to vb.net

Scheduled Pinned Locked Moved Visual Basic
csharphelptutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hassanasp
    wrote on last edited by
    #1

    i try to convert c# code to vb.net code but i have probelm with execute displayMessage in Main sub .I am trying to covert the code at many websites which provide coverting service but most of it have the same error can any one concert it to vb.net code using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace ConsoleApplication13 { class Program { private class Massegeinfo { private int iterations; private string massage; public Massegeinfo (int iterations,string massage) { this.iterations=iterations; this.massage=massage; } public int Iterations{get{return iterations;}} public string Massage{get{return massage;}} } public static void displayMessage(object state) { Massegeinfo config=state as Massegeinfo ; if (config==null) { for(int count=0;count<3;count++) { Console.WriteLine("a thread pool example"); Thread.Sleep(1000); } } else { for(int count=0;count < config.Iterations;count++) { Console.WriteLine(config.Massage); Thread.Sleep(1000); } } } static void Main(string[] args) { ThreadPool.QueueUserWorkItem(displayMessage); Massegeinfo info = new Massegeinfo(5, "A thread pool example with arguments"); ThreadPool.QueueUserWorkItem(displayMessage, info); Console.WriteLine("Main method complete. press enter"); Console.ReadLine(); } } }

    Ahmed hassan

    H D 2 Replies Last reply
    0
    • H hassanasp

      i try to convert c# code to vb.net code but i have probelm with execute displayMessage in Main sub .I am trying to covert the code at many websites which provide coverting service but most of it have the same error can any one concert it to vb.net code using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace ConsoleApplication13 { class Program { private class Massegeinfo { private int iterations; private string massage; public Massegeinfo (int iterations,string massage) { this.iterations=iterations; this.massage=massage; } public int Iterations{get{return iterations;}} public string Massage{get{return massage;}} } public static void displayMessage(object state) { Massegeinfo config=state as Massegeinfo ; if (config==null) { for(int count=0;count<3;count++) { Console.WriteLine("a thread pool example"); Thread.Sleep(1000); } } else { for(int count=0;count < config.Iterations;count++) { Console.WriteLine(config.Massage); Thread.Sleep(1000); } } } static void Main(string[] args) { ThreadPool.QueueUserWorkItem(displayMessage); Massegeinfo info = new Massegeinfo(5, "A thread pool example with arguments"); ThreadPool.QueueUserWorkItem(displayMessage, info); Console.WriteLine("Main method complete. press enter"); Console.ReadLine(); } } }

      Ahmed hassan

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      What is the error? I suspect it is to do with the for-next loop and the indexes used, but without knowing the error you are getting it is difficult to be sure.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      H 1 Reply Last reply
      0
      • H Henry Minute

        What is the error? I suspect it is to do with the for-next loop and the indexes used, but without knowing the error you are getting it is difficult to be sure.

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        H Offline
        H Offline
        hassanasp
        wrote on last edited by
        #3

        i tried to convert this code i made class in seperate file Imports System.Threading Class program Private Class MessageInfo Private iteration As Integer Private message As String Public Sub New(ByVal iteration As Integer, ByVal message As String) Me.iteration = iteration Me.message = message End Sub Public ReadOnly Property Iterations() As Integer Get Return iteration End Get End Property Public ReadOnly Property Messages() As String Get Return message End Get End Property End Class Public Shared Sub DisplayMessage(ByVal state As Object) Dim config As MessageInfo = TryCast(state, MessageInfo) If config Is Nothing Then Dim count As Integer For count = 0 To 2 Step count + 1 Console.WriteLine("a thread pool example") Thread.Sleep(1000) Next Else Dim count As Integer For count = 0 To config.Iterations - 1 Step -1 Console.WriteLine(config.Messages) Thread.Sleep(1000) Next End If End Sub End Class 'and try to use it in sub Main Imports System.Threading Module Module1 Sub Main() ThreadPool.QueueUserWorkItem(MessageInfo.DisplayMessage) Dim info As New MessageInfo(5, "a thread pool example with arguments") ThreadPool.QueueUserWorkItem(MessageInfo.DisplayMessage, info) Console.WriteLine("Main method complete. press enter") Console.ReadLine() End Sub End Module error Error 1,2,3 Type 'MessageInfo' is not defined. C:\Documents and Settings\Sokar\My Documents\Visual Studio 2005\Projects\ConsoleApplication16\ConsoleApplication16\Module1.vb 7 25 ConsoleApplication16

        Ahmed hassan

        D 1 Reply Last reply
        0
        • H hassanasp

          i tried to convert this code i made class in seperate file Imports System.Threading Class program Private Class MessageInfo Private iteration As Integer Private message As String Public Sub New(ByVal iteration As Integer, ByVal message As String) Me.iteration = iteration Me.message = message End Sub Public ReadOnly Property Iterations() As Integer Get Return iteration End Get End Property Public ReadOnly Property Messages() As String Get Return message End Get End Property End Class Public Shared Sub DisplayMessage(ByVal state As Object) Dim config As MessageInfo = TryCast(state, MessageInfo) If config Is Nothing Then Dim count As Integer For count = 0 To 2 Step count + 1 Console.WriteLine("a thread pool example") Thread.Sleep(1000) Next Else Dim count As Integer For count = 0 To config.Iterations - 1 Step -1 Console.WriteLine(config.Messages) Thread.Sleep(1000) Next End If End Sub End Class 'and try to use it in sub Main Imports System.Threading Module Module1 Sub Main() ThreadPool.QueueUserWorkItem(MessageInfo.DisplayMessage) Dim info As New MessageInfo(5, "a thread pool example with arguments") ThreadPool.QueueUserWorkItem(MessageInfo.DisplayMessage, info) Console.WriteLine("Main method complete. press enter") Console.ReadLine() End Sub End Module error Error 1,2,3 Type 'MessageInfo' is not defined. C:\Documents and Settings\Sokar\My Documents\Visual Studio 2005\Projects\ConsoleApplication16\ConsoleApplication16\Module1.vb 7 25 ConsoleApplication16

          Ahmed hassan

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          The code won't compile until you supply the library and reference supplying the MessageInfo class. This is not a class that comes in the .NET Framework. You'll have to go back to where you got the code from and see if you can find any information on where this class is comming from.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008
          But no longer in 2009...

          1 Reply Last reply
          0
          • H hassanasp

            i try to convert c# code to vb.net code but i have probelm with execute displayMessage in Main sub .I am trying to covert the code at many websites which provide coverting service but most of it have the same error can any one concert it to vb.net code using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace ConsoleApplication13 { class Program { private class Massegeinfo { private int iterations; private string massage; public Massegeinfo (int iterations,string massage) { this.iterations=iterations; this.massage=massage; } public int Iterations{get{return iterations;}} public string Massage{get{return massage;}} } public static void displayMessage(object state) { Massegeinfo config=state as Massegeinfo ; if (config==null) { for(int count=0;count<3;count++) { Console.WriteLine("a thread pool example"); Thread.Sleep(1000); } } else { for(int count=0;count < config.Iterations;count++) { Console.WriteLine(config.Massage); Thread.Sleep(1000); } } } static void Main(string[] args) { ThreadPool.QueueUserWorkItem(displayMessage); Massegeinfo info = new Massegeinfo(5, "A thread pool example with arguments"); ThreadPool.QueueUserWorkItem(displayMessage, info); Console.WriteLine("Main method complete. press enter"); Console.ReadLine(); } } }

            Ahmed hassan

            D Offline
            D Offline
            Dave Doknjas
            wrote on last edited by
            #5

            Imports System
            Imports System.Collections.Generic
            Imports System.Text
            Imports System.Threading

            Namespace ConsoleApplication13
            Friend Class Program
            Private Class Massegeinfo
            'INSTANT VB NOTE: The variable iterations was renamed since Visual Basic does not allow class members with the same name:
            Private iterations_Renamed As Integer
            'INSTANT VB NOTE: The variable massage was renamed since Visual Basic does not allow class members with the same name:
            Private massage_Renamed As String
            Public Sub New(ByVal iterations As Integer, ByVal massage As String)
            Me.iterations_Renamed=iterations
            Me.massage_Renamed=massage
            End Sub
            Public ReadOnly Property Iterations() As Integer
            Get
            Return iterations_Renamed
            End Get
            End Property
            Public ReadOnly Property Massage() As String
            Get
            Return massage_Renamed
            End Get
            End Property
            End Class

            	Public Shared Sub displayMessage(ByVal state As Object)
            		Dim config As Massegeinfo=TryCast(state, Massegeinfo)
            		If config Is Nothing Then
            			For count As Integer = 0 To 2
            				Console.WriteLine("a thread pool example")
            				Thread.Sleep(1000)
            			Next count
            		Else
            			For count As Integer = 0 To config.Iterations - 1
            				Console.WriteLine(config.Massage)
            				Thread.Sleep(1000)
            			Next count
            		End If
            
            	End Sub
            
            	Shared Sub Main(ByVal args() As String)
            		ThreadPool.QueueUserWorkItem(AddressOf displayMessage)
            		Dim info As New Massegeinfo(5, "A thread pool example with arguments")
            		ThreadPool.QueueUserWorkItem(AddressOf displayMessage, info)
            		Console.WriteLine("Main method complete. press enter")
            		Console.ReadLine()
            	End Sub
            End Class
            

            End Namespace

            David Anton http://www.tangiblesoftwaresolutions.com Convert VB to C#, C++, or Java Convert C# to VB, C++, or Java Convert C++ to C#, VB, or Java Convert Java to C#, C++, or VB

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups