分享
 
 
 

方便地启动Oracle服务(VB.NET 2005 Windows服务操控与多线程)

王朝oracle·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

Oracle 9i有多个系统服务必须都启动之后才能正常工作,但逐个启动比较费事,多数学习Oracle但机器又不是太好的朋友也不能容忍每次都自动启动Oracle服务(那样512MB的内存在启动时就所剩无几了),所以通常都是要用了再启动,这里给出了批量启动windows系统服务的一个例子,介绍了操控windows系统服务的技巧:

首先新建一个Windows Application工程,取名为Oracle Starter

粘贴如下代码文件:

Form1.Designer.vb

Partial Public Class Form1

Inherits System.Windows.Forms.Form

<System.Diagnostics.DebuggerNonUserCode()> _

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

End Sub

'Form overrides dispose to clean up the component list.

<System.Diagnostics.DebuggerNonUserCode()> _

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing AndAlso components IsNot Nothing Then

components.Dispose()

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

<System.Diagnostics.DebuggerStepThrough()> _

Private Sub InitializeComponent()

Me.Label1 = New System.Windows.Forms.Label

Me.ListBox1 = New System.Windows.Forms.ListBox

Me.Button1 = New System.Windows.Forms.Button

Me.Button2 = New System.Windows.Forms.Button

Me.SuspendLayout()

'

'Label1

'

Me.Label1.AutoSize = True

Me.Label1.Font = New System.Drawing.Font("Tahoma", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))

Me.Label1.Location = New System.Drawing.Point(13, 13)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing.Size(122, 22)

Me.Label1.TabIndex = 0

Me.Label1.Text = "Oracle Starter"

'

'ListBox1

'

Me.ListBox1.Font = New System.Drawing.Font("Tahoma", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))

Me.ListBox1.FormattingEnabled = True

Me.ListBox1.ItemHeight = 19

Me.ListBox1.Location = New System.Drawing.Point(13, 75)

Me.ListBox1.Name = "ListBox1"

Me.ListBox1.Size = New System.Drawing.Size(436, 175)

Me.ListBox1.TabIndex = 1

'

'Button1

'

Me.Button1.Location = New System.Drawing.Point(322, 257)

Me.Button1.Name = "Button1"

Me.Button1.Size = New System.Drawing.Size(127, 34)

Me.Button1.TabIndex = 2

Me.Button1.Text = "Stop all services"

'

'Button2

'

Me.Button2.Location = New System.Drawing.Point(188, 258)

Me.Button2.Name = "Button2"

Me.Button2.Size = New System.Drawing.Size(127, 34)

Me.Button2.TabIndex = 3

Me.Button2.Text = "Start all servies"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)

Me.ClientSize = New System.Drawing.Size(461, 304)

Me.Controls.Add(Me.Button2)

Me.Controls.Add(Me.Button1)

Me.Controls.Add(Me.ListBox1)

Me.Controls.Add(Me.Label1)

Me.Name = "Form1"

Me.Text = "Oracle Starter"

Me.ResumeLayout(False)

Me.PerformLayout()

End Sub

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents ListBox1 As System.Windows.Forms.ListBox

Friend WithEvents Button1 As System.Windows.Forms.Button

Friend WithEvents Button2 As System.Windows.Forms.Button

End Class

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有