Click here to Skip to main content
15,886,067 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Queue and Stack Pin
DJHJr17-Apr-14 9:07
DJHJr17-Apr-14 9:07 
GeneralRe: Queue and Stack Pin
Eddy Vluggen17-Apr-14 10:24
professionalEddy Vluggen17-Apr-14 10:24 
Questionfilesystemwatcher possible infinite loop Pin
Tony Snowden17-Apr-14 0:20
Tony Snowden17-Apr-14 0:20 
AnswerRe: filesystemwatcher possible infinite loop Pin
Richard Andrew x6417-Apr-14 0:45
professionalRichard Andrew x6417-Apr-14 0:45 
GeneralRe: filesystemwatcher possible infinite loop Pin
Tony Snowden17-Apr-14 1:07
Tony Snowden17-Apr-14 1:07 
QuestionHow to Run Transparent Flash Files Over a Running Video in VB Pin
NAVEEN SONI16-Apr-14 17:56
NAVEEN SONI16-Apr-14 17:56 
QuestionPass a string to a control on a form from a remoting connection Pin
ParadoxLiving15-Apr-14 20:27
ParadoxLiving15-Apr-14 20:27 
AnswerRe: Pass a string to a control on a form from a remoting connection Pin
Alan N16-Apr-14 4:48
Alan N16-Apr-14 4:48 
Hi,
In all the Microsoft examples I've seen, the server is dumb, i.e. it does not interact with the remotable objects. This fairly common requirement is quite easy to implement, once you know how. The trick is to create a standard object on the server and then publish it for remoting using System.Runtime.Remoting.RemotingServices.Marshal.

Here's the example based on that MS ISharedInterface
VB
Public Interface ISharedInterface
  Function HelloWorld(input As String) As String
End Interface


This is the remotable class, implementing the interface, which will be created as a local object on the server. For simplicity in the example I just pass a reference to a TextBox to the constructor. The HelloWorld function executes on a non UI thread and has to Invoke the TextBox.
VB
Public Class MessageReceiver Inherits MarshalByRefObject Implements ISharedInterface
  Private ReadOnly log As TextBox
  Private Delegate Sub Update(text As [String])

  Public Sub New(log As TextBox)
    Me.log = log
  End Sub

  ' ISharedInterface function
  Public Function HelloWorld(input As String) As String
    log.Invoke(New Update(AddressOf UpdateTextBox), input)
    Return input
  End Function

  Private Sub UpdateTextBox(text As [String])
    log.AppendText(text)
    log.AppendText(Environment.NewLine)
  End Sub

  Public Overrides Function InitializeLifetimeService() As Object
    Return Nothing
  End Function
End Class


Now we have the 'abbreviated' form class which is the UI for the server. In it I haven't shown the declaration for a multiline TextBox named logTextBox. The important stuff is the creation of a local object followed by separate 'remoting'. Most MS examples use tcp but I've configured for ipc as that is more appropriate for process to process communication on a single machine.
VB
Public Partial Class MainForm Inherits Form
  Private server As IpcServerChannel
  Private receiver As MessageReceiver

  Protected Overrides Sub OnShown(e As EventArgs)
    MyBase.OnShown(e)
    ' create local object and give it the textbox reference
    receiver = New MessageReceiver(logTextBox)

    ' Create the server channel
    ' remote object name will be "ipc://IpcPortName/ServerObject.rem"
    server = New IpcServerChannel("IpcPortName")
    ChannelServices.RegisterChannel(server, False)
    logTextBox.AppendText("IpcServerChannel created")
    logTextBox.AppendText(Environment.NewLine)

    ' publish the local object
    RemotingServices.Marshal(receiver, "ServerObject.rem")
  End Sub
End Class

Finally for completeness there is a console based client which fires a few messages at the server.
VB
Public NotInheritable Class ClientApp
  Private Sub New()
  End Sub

  Private Shared remoteObject As ISharedInterface

  Public Shared Sub Main(args As String())
    Try
      remoteObject = DirectCast(Activator.GetObject(GetType(ISharedInterface), "ipc://IpcPortName/ServerObject.rem"), ISharedInterface)
      For i As Int32 = 0 To 4
        Console.WriteLine("  " & remoteObject.HelloWorld("Hi Server " & i))
        Thread.Sleep(2000)
      Next
    Catch re As System.Runtime.Remoting.RemotingException
      Console.WriteLine(re)
    End Try
    Console.WriteLine("Press enter to end...")
    Console.ReadLine()
  End Sub
End Class


All that code was converted from c# with http://www.developerfusion.com/tools/convert/csharp-to-vb/[^] so I'm not totally to blame if it doesn't work!

Alan.
GeneralRe: Pass a string to a control on a form from a remoting connection Pin
ParadoxLiving16-Apr-14 16:07
ParadoxLiving16-Apr-14 16:07 
QuestionStart another process as admin Pin
Dominick Marciano15-Apr-14 3:52
professionalDominick Marciano15-Apr-14 3:52 
AnswerRe: Start another process as admin Pin
Bernhard Hiller15-Apr-14 22:25
Bernhard Hiller15-Apr-14 22:25 
GeneralRe: Start another process as admin Pin
Dominick Marciano16-Apr-14 8:22
professionalDominick Marciano16-Apr-14 8:22 
GeneralRe: Start another process as admin Pin
Dave Kreskowiak16-Apr-14 9:41
mveDave Kreskowiak16-Apr-14 9:41 
AnswerRe: Start another process as admin Pin
helfetho17-Apr-14 0:56
helfetho17-Apr-14 0:56 
GeneralRe: Start another process as admin Pin
Dominick Marciano17-Apr-14 4:35
professionalDominick Marciano17-Apr-14 4:35 
GeneralRe: Start another process as admin Pin
helfetho17-Apr-14 5:48
helfetho17-Apr-14 5:48 
QuestionNo value given for one or more required parameters. Pin
jkirkerx14-Apr-14 12:16
professionaljkirkerx14-Apr-14 12:16 
Answer[SOLVED] Pin
jkirkerx14-Apr-14 12:34
professionaljkirkerx14-Apr-14 12:34 
GeneralRe: [SOLVED] Pin
Tim Carmichael15-Apr-14 2:04
Tim Carmichael15-Apr-14 2:04 
GeneralRe: [SOLVED] Pin
jkirkerx15-Apr-14 6:32
professionaljkirkerx15-Apr-14 6:32 
QuestionRe: how to import all csv files in a drive to database ? Pin
sensizbenlik14-Apr-14 10:10
sensizbenlik14-Apr-14 10:10 
GeneralRe: how to import all csv files in a drive to database ? Pin
PIEBALDconsult14-Apr-14 10:40
mvePIEBALDconsult14-Apr-14 10:40 
AnswerRe: how to import all csv files in a drive to database ? Pin
Wes Aday14-Apr-14 11:14
professionalWes Aday14-Apr-14 11:14 
GeneralRe: how to import all csv files in a drive to database ? Pin
sensizbenlik14-Apr-14 14:25
sensizbenlik14-Apr-14 14:25 
GeneralRe: how to import all csv files in a drive to database ? Pin
Wes Aday14-Apr-14 14:53
professionalWes Aday14-Apr-14 14:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.