我的第一个表单只有一个通知图标并轮询一些结果,如果结果符合标准并引发警报,则会打开 form2。
我的问题是一旦 form2 打开结果并播放警报 mp3,我想用来停止 mp3 播放的页面上的按钮根本没有响应。
编辑,我已将我的代码更改为我目前拥有的代码。按照建议使用后台工作人员时,Form2 变得无响应。
这是表格1
Public Class Form1
Public Property waittimer As Integer = 60000
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
BackgroundWorker1.WorkerSupportsCancellation = True
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
Form2.Close()
Application.Exit()
End Sub
Private Sub wait(ByVal interval As Integer)
Dim stopW As New Stopwatch
stopW.Start()
Do While stopW.ElapsedMilliseconds < interval
' Allows your UI to remain responsive
Application.DoEvents()
Loop
stopW.Stop()
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim firsttime As Boolean = True
Dim myForm2 As Form2
' While True
Try
' Create a request for the URL.
Dim request As WebRequest = _
WebRequest.Create("http://example/example.aspx")
' If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials
' Get the response.
Dim response As WebResponse = request.GetResponse()
' Display the status.
Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
' Get the stream containing content returned by the server.
Dim dataStream As Stream = response.GetResponseStream()
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)
' Read the content.
Dim responseFromServer As String = reader.ReadToEnd()
' Display the content.
Console.WriteLine(responseFromServer)
' Clean up the streams and the response.
reader.Close()
response.Close()
Dim responseArray() As String
responseArray = Split(responseFromServer, "|")
Form2.maxcalls = responseArray(0)
Form2.cph = responseArray(1)
Form2.mht = responseArray(2)
Form2.alarm = responseArray(3)
'Form2.Show()
If Form2.alarm = True Then
myForm2 = New Form2()
Form2.Show()
End If
Application.DoEvents()
System.Threading.Thread.Sleep(waittimer)
' wait(waittimer)
If waittimer = 1800000 Then
waittimer = 60000
End If
Catch ex As Exception
End Try
' End While
End Sub
End Class
这是表格2
Public Class Form2
Public Property maxcalls As Integer
Public Property cph As Integer
Public Property mht As Integer
Public Property alarm As Boolean
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
InitializeComponent()
startsong()
End Sub
Sub startsong()
MHTvalue.Text = mht.ToString
Maxcallsvalue.Text = maxcalls
CPHvalue.Text = cph
Dim audio As New AudioFile("C:\example\Help.mp3")
audio.Play()
Application.DoEvents()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MessageBox.Show("test")
End Sub
结束类
任何帮助将不胜感激。