locked
Problem to convert C# code to VB.Net RRS feed

  • Question

  • User986610096 posted

    Hello,

    I tried to convert a C# code to VB.Net code into my asp.net app but i get an error message about how call an Event.
    The C# code is following :

                    try
                    {
                        string messageQueuePath = @".\private$\EmailQueue";
                        _msmqQueue = new MessageQueue(messageQueuePath);
                        _msmqQueue.Formatter =  new BinaryMessageFormatter();
                        _msmqQueue.MessageReadPropertyFilter.SetAll();
                        _msmqQueue.ReceiveCompleted+=new ReceiveCompletedEventHandler(msmqQueue_ReceiveCompleted);
                        _msmqQueue.BeginReceive();
                        Console.WriteLine("Enter 'A' to Exit ");
                        while(Console.ReadKey().Key!=ConsoleKey.A)
                        {
                            Thread.Sleep(0);
                        }
    
                    }
                    catch(Exception oEx)
                    {
                        Console.WriteLine(oEx.Message);
                        Console.ReadKey();
                    }


    I transformed all parts of this code except this :

     

    _msmqQueue.ReceiveCompleted+=new ReceiveCompletedEventHandler(msmqQueue_ReceiveCompleted); 


    The error message ask me to use RaiseEvent to call ReceiveCompleted because it is an Event when  i use this conversion :

    _msmqQueue.ReceiveCompleted += New ReceiveCompletedEventHandler(AddressOf msmqQueue_ReceiveCompleted)


    I used AddressOf to avoid another error but i always have tne Event Error.

    Thank's a lot for any help

     

     

     

     

     

     

     

     

    Sunday, November 18, 2012 6:44 PM

Answers

  • User397347636 posted
    AddHandler _msmqQueue.ReceiveCompleted, AddressOf msmqQueue_ReceiveCompleted
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 19, 2012 12:21 AM

All replies

  • User397347636 posted
    AddHandler _msmqQueue.ReceiveCompleted, AddressOf msmqQueue_ReceiveCompleted
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 19, 2012 12:21 AM
  • User-1971614856 posted
    Try
    	Dim messageQueuePath As String = ".\private$\EmailQueue"
    	_msmqQueue = New MessageQueue(messageQueuePath)
    	_msmqQueue.Formatter = New BinaryMessageFormatter()
    	_msmqQueue.MessageReadPropertyFilter.SetAll()
    	_msmqQueue.ReceiveCompleted += New ReceiveCompletedEventHandler(msmqQueue_ReceiveCompleted)
    	_msmqQueue.BeginReceive()
    	Console.WriteLine("Enter 'A' to Exit ")
    	While Console.ReadKey().Key <> ConsoleKey.A
    		Thread.Sleep(0)
    
    	End While
    Catch oEx As Exception
    	Console.WriteLine(oEx.Message)
    	Console.ReadKey()
    End Try
    

    http://converter.telerik.com/

    http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Monday, November 19, 2012 12:28 AM
  • User986610096 posted

    hello,

    Thank's for your reply, but if you convert this sentence
    _msmqQueue.ReceiveCompleted+=new ReceiveCompletedEventHandler(msmqQueue_ReceiveCompleted);
    by this one :
    AddHandler _msmqQueue.ReceiveCompleted, AddressOf msmqQueue_ReceiveCompleted
    Where is the '+=' operator ?
    Is there a risk without this operator to lost some informations?

    Thank's in advance for your reply

     

    Monday, November 19, 2012 5:48 AM
  • User397347636 posted

    There's no risk - VB does things differently than C#.  Simple as that.

    Monday, November 19, 2012 3:46 PM