科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道Windows服务:方便地启动Oracle服务

Windows服务:方便地启动Oracle服务

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

Oracle 9i有多个系统服务必须都启动之后才能正常工作,但逐个启动比较费事,多数学习Oracle但机器又不是太好的朋友也不能容忍每次都自动启动Oracle服务(那样512MB的内存在启动时就所剩无几了),所以通常都是要用了再启动。

作者:中国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领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章