1

Windowsサービスで関数を使用して、データをvb.netアプリケーションに返すことはできますか?

これがWindowsサービスのサンプルコードです。

 Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.
        EventLog1.WriteEntry("In OnStart")
    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
        EventLog1.WriteEntry("In OnStop.")
    End Sub
    Protected Overrides Sub OnContinue()
        EventLog1.WriteEntry("In OnContinue.")
    End Sub
    Protected Overrides Sub OnCustomCommand(ByVal command As Integer)
        Dim mymsg As String
        Dim servicestorun As New System.ServiceProcess.ServiceBase
        If (command < 128) Then
            MyBase.OnCustomCommand(command)
        Else
            Select Case command
                Case 129
                    mymsg = "i want this msg to my vb.net application"
                Case Else
            End Select
        End If

    End Sub

これがvb.netアプリケーションでの私のコードです:

Dim myServiceController As New System.ServiceProcess.ServiceController("MyNewService")

        Dim status As String
        Try
            myServiceController.ExecuteCommand(129)
 ' i want to get the msg from my windows service "i want this msg to my vb.net application"
            status = "Custom Command Executed Successfully!"
        Catch ex As Exception
            status = "Failed To Execute Custom Command! " & ex.Message
        End Try

助けが必要です。

4

1 に答える 1

1

Windows サービスを WCF ホストとして使用できます。たとえば、http://msdn.microsoft.com/en-us/library/ms733069.aspxを参照してください

同じマシンでの通信には、名前付きパイプ (NetNamedPipeBinding) をお勧めします。WCF を使用せずに名前付きパイプを使用することもできます (http://stackoverflow.com/questions/4303154/)

于 2012-08-31T11:49:51.617 に答える