Private Sub Button1_Click ( ByVal sender As System.Object , ByVal e As System.EventArgs ) Handles Button1.Click thThreadRead = New Thread ( New ThreadStart ( AddressOf Listen ) ) ''以Listen过程来初始化线程实例 thThreadRead.Start ( ) ''启动线程 Button1.Enabled = False Label1.Text = "服务已经启动!" Label1.ForeColor = Color.Red End Sub 13. 用下列代码替换Form1.vb中的Dispose过程,下面代码的作用是重新定义Dispose过程,在Dispose过程手动清除使用的资源,回收垃圾:
Protected Overloads Overrides Sub Dispose ( ByVal disposing As Boolean ) Try thThreadRead.Abort ( ) ''中止线程 tlTcpListen.Stop ( ) ''关闭侦听 tcClient.Close ( ) nsStream.Close ( ) srRead.Close ( ) ''释放资源 Catch End Try If disposing Then If Not ( components Is Nothing ) Then components.Dispose ( ) End If End If MyBase.Dispose ( disposing ) End Sub 14. 至此在上述步骤都正确执行后,【服务器端程序】项目的全部工作就完成了。编译、生成可执行文件后,接着介绍客户端程序的实现步骤。