在Service中如何应用invoke进行委托反射?
vb.net吧
全部回复
仅看楼主
level 1
代码在2楼
2014年06月29日 07点06分 1
level 1
[code=text]Imports System.Object
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading '多线程
Imports System.Threading.Tasks '任务?可能是05之后增加的。
Public Class TSRMainSerice
Private _Listener As TcpListener
Private _Connections As New List(Of ConnectionInfo)
Private _ConnectionMontior As Task
Public strListenPort As String
Protected Overrides Sub OnStart(ByVal args() As String)
' 请在此处添加代码以启动您的服务。此方法应完成设置工作,
' 以使您的服务开始工作。
'StartStopButton.Image = My.Resources.Resources.StopServer
'启动端口侦听器
strListenPort = 5004
_Listener = New TcpListener(IPAddress.Any, CInt(strListenPort))
_Listener.Start()
'启动侦听
Dim monitor As New MonitorInfo(_Listener, _Connections)
ListenForClient(monitor)
_ConnectionMontior = Task.Factory.StartNew(AddressOf DoMonitorConnections, monitor, TaskCreationOptions.LongRunning)
End Sub
Protected Overrides Sub OnStop()
' 在此处添加代码以执行任何必要的拆解操作,从而停止您的服务。
'StartStopButton.Text = "Start"
'StartStopButton.Image = My.Resources.Resources.StartServer
CType(_ConnectionMontior.AsyncState, MonitorInfo).Cancel = True
_Listener.Stop()
_Listener = Nothing
End Sub
' Private Sub PortTextBox_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles PortTextBox.Validating
' Dim deltaPort As Integer
' If Not Integer.TryParse(strListenPort, deltaPort) OrElse deltaPort < 1 OrElse deltaPort > 65535 Then
' MessageBox.Show("Port number must be an integer between 1 and 65535.", "Invalid Port Number", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
' PortTextBox.SelectAll()
' e.Cancel = True
' End If
' End Sub
Private Sub ListenForClient(monitor As MonitorInfo)
Dim info As New ConnectionInfo(monitor)
_Listener.BeginAcceptTcpClient(AddressOf DoAcceptClient, info)
End Sub
Private Sub DoAcceptClient(result As IAsyncResult)
Dim monitorInfo As MonitorInfo = CType(_ConnectionMontior.AsyncState, MonitorInfo)
If monitorInfo.Listener IsNot Nothing AndAlso Not monitorInfo.Cancel Then
Dim info As ConnectionInfo = CType(result.AsyncState, ConnectionInfo)
monitorInfo.Connections.Add(info)
info.AcceptClient(result)
ListenForClient(monitorInfo)
info.AwaitData()
Dim doUpdateConnectionCountLabel As New Action(AddressOf UpdateConnectionCount)
Invoke(doUpdateConnectionCount)
End If
End Sub
Private Sub UpdateConnectionCountLabel()
writeLog(String.Format("{0} Connections", _Connections.Count))
End Sub
End Class
[/code]
编译时提示“Invoke没有声明”
2014年06月29日 07点06分 2
level 1
好难呀。。。。
2014年06月30日 08点06分 3
1