扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:中国IT实验室 来源:中国IT实验室 2007年10月7日
关键字: ORACLE
在本页阅读全文(共2页)
Form1.vb
Imports System.ServiceProcess
Imports System.Threading
Public Class Form1
''''Private procName As String
Private procArray(5) As String
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
procArray(0) = "OracleMTSRecoveryService"
procArray(1) = "OracleOraHome92Agent"
procArray(2) = "OracleOraHome92TNSListener"
procArray(3) = "OracleServiceSFSVDB"
procArray(4) = "OracleOraHome92HTTPServer"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim backThread As Thread
Dim i As Int16
For i = 0 To 4
backThread = New Thread(AddressOf procClass.StopProc)
backThread.IsBackground = True
procClass.procName = procArray(i)
Label1.Text = "Stopping service: " + procClass.procName + " ..."
Me.Refresh()
backThread.Start()
backThread.Join()
ListBox1.Items.Add("Service: " + procClass.procName + " Stopped")
Me.Refresh()
backThread = Nothing
Next
Label1.Text = "All services stopped"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim backThread As Thread
Dim i As Int16
For i = 0 To 4
backThread = New Thread(AddressOf procClass.StartProc)
procClass.procName = procArray(i)
Label1.Text = "Starting service: " + procClass.procName + " ..."
Me.Refresh()
backThread.Start()
backThread.Join()
ListBox1.Items.Add("Service: " + procClass.procName + " Started")
Me.Refresh()
backThread = Nothing
Next
Label1.Text = "All services started"
End Sub
Public Class procClass
Public Shared procName As String
Public Shared Sub StopProc()
Dim servController1 As ServiceController = New ServiceController(procName)
If servController1.Status = ServiceControllerStatus.Stopped Then
ElseIf servController1.Status = ServiceControllerStatus.Paused Then
servController1.Stop()
servController1.WaitForStatus(ServiceControllerStatus.Stopped)
ElseIf servController1.Status = ServiceControllerStatus.Running Then
servController1.Stop()
servController1.WaitForStatus(ServiceControllerStatus.Stopped)
End If
End Sub
Public Shared Sub StartProc()
Dim servController1 As ServiceController = New ServiceController(procName)
If servController1.Status = ServiceControllerStatus.Running Then
ElseIf servController1.Status = ServiceControllerStatus.Paused Then
servController1.Continue()
servController1.WaitForStatus(ServiceControllerStatus.Running)
ElseIf servController1.Status = ServiceControllerStatus.Stopped Then
servController1.Start()
servController1.WaitForStatus(ServiceControllerStatus.Running)
End If
End Sub
End Class
End Class
总结:
这个实例只是运用了系统服务控制的基本功能,高级功能还不甚了解,对于多线程的运用还不是很明确,望大家指正
改进:
程序在运行时如果焦点离开,用户界面便会锁死,虽然尝试了多线程,仍然不理想,应该还Join()方法有关,多次修正未果,请高手指点,谢谢!
测试平台:
Windows Server 2003,Visual VB.NET 2005 Beta 1
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者