Problemer med IPC pipe lukket
Hej eksperter.. jeg har et mindre problem med IPC, jeg er ved at lege med IPC, da jeg skal lave en service til .Net 2.0koden virker ikke helt som den skal.. når jeg starter den, virker den.. men når jeg genstarter, kan den ikke finde pipen, og siger "pipe lukket"
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
Imports System.Security.Principal
Public Class TestService
Public Property ipc As IpcRemoteObject
Private Shared FILE_NAME As String = "C:\testfil.txt"
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
ipc.Counter = ipc.Counter + 1
ipc.text = "Startet"
ipc.args = args
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
ipc.text = "Stoppet"
End Sub
Protected Overrides Sub OnContinue()
ipc.text = "Continued"
End Sub
Protected Overrides Sub OnPause()
ipc.text = "Paused"
End Sub
Public Sub New()
' This call is required by the designer.
InitializeComponent()
Try
' Add any initialization after the InitializeComponent() call.
' Get SID code for the EveryOne user
Dim sid As SecurityIdentifier = New SecurityIdentifier(WellKnownSidType.WorldSid, Nothing)
' Get the NT account related to the SID
Dim account As NTAccount = sid.Translate(GetType(NTAccount))
Dim properties As New Hashtable()
properties.Add("portName", "testport")
properties.Add("exclusiveAddressUse", False)
properties.Add("authorizedGroup", account.Value)
Dim channel As New IpcServerChannel(properties, Nothing)
ChannelServices.RegisterChannel(channel, True)
ipc = New IpcRemoteObject()
RemotingServices.Marshal(ipc, "status", GetType(IpcRemoteObject))
Catch ex As Exception
WriteToFile(ex.Message)
End Try
End Sub
Public Sub WriteToFile(ByVal text As String)
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
objWriter.WriteLine(text)
objWriter.Close()
End If
End Sub
End Class