以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]等待窗口经常卡死 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=169397) |
-- 作者:天一生水 -- 发布时间:2021/6/15 11:25:00 -- [求助]等待窗口经常卡死 老师好! 这个等待窗口运行时经常卡死,需要启动任务管理器关闭后重新打开软件,运行的代码耗时不多,再次运行又可能正常。是哪里的问题? 原贴:http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=152101 全局代码 以下内容只有回复后才可以浏览 Public Class FrmWaitingBox Inherits System.Windows.Forms.Form Public Sub New(ByVal Method As EventHandler(Of EventArgs), ByVal msg As String) InitializeComponent() If Not String.IsNullOrEmpty(msg) Then lblTip.Text = msg End If _Method = Method End Sub Private _Method As EventHandler(Of EventArgs) Private asyncResult As IAsyncResult Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) If asyncResult.IsCompleted Then Me.Close() End If End Sub Private Sub FrmWaitingBox_Shown(ByVal sender As Object, ByVal e As EventArgs) asyncResult = _Method.BeginInvoke(Nothing, Nothing, Nothing,Nothing) End Sub Private components As System.ComponentModel.IContainer = Nothing Protected Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso (components IsNot Nothing) Then components.Dispose() End If MyBase.Dispose(disposing) End Sub Private Sub InitializeComponent() Me.components = New System.ComponentModel.Container() Me.pictureBox1 = New System.Windows.Forms.PictureBox() Me.lblTip = New System.Windows.Forms.Label() Me.timer1 = New System.Windows.Forms.Timer(Me.components) DirectCast(Me.pictureBox1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout()
\' pictureBox1 Me.pictureBox1.Image = System.Drawing.Image.FromFile(ProjectPath & "Loading.gif") Me.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill Me.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage Me.pictureBox1.Name = "pictureBox1"
\' lblTip
Me.lblTip.AutoSize = True
Me.lblTip.BackColor = System.Drawing.Color.FromArgb((CInt((CByte(20)))), (CInt((CByte(50)))), (CInt((CByte(84)))))
Me.lblTip.Font = New System.Drawing.Font("微软雅黑", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (CByte(134))) Me.lblTip.ForeColor = System.Drawing.Color.White
Me.lblTip.Location = New System.Drawing.Point(130, 223)
Me.lblTip.Name = "lblTip"
Me.lblTip.Size = New System.Drawing.Size(203, 25)
Me.lblTip.Text = "正在处理数据,请等待..."
\' timer1
Me.timer1.Enabled = True
Me.timer1.Interval = 500
AddHandler timer1.Tick, AddressOf timer1_Tick
\' FrmWaitingBox
Me.AutoScaleDimensions = New System.Drawing.SizeF(6F, 12F)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.BackColor = System.Drawing.Color.Silver
Me.ClientSize = New System.Drawing.Size(460, 280)
Me.Controls.Add(Me.lblTip)
Me.Controls.Add(Me.pictureBox1) Me.MaximizeBox = False Me.MinimizeBox = False Me.Name = "FrmWaitingBox" Me.Text = "FrmWaitingBox" Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.TransparencyKey = Color.red Me.OPacity = 0.9 Me.ShowInTaskbar = False
AddHandler Me.Shown, AddressOf FrmWaitingBox_Shown
DirectCast(Me.pictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout() End Sub Private pictureBox1 As System.Windows.Forms.PictureBox Private lblTip As System.Windows.Forms.Label Private WithEvents timer1 As System.Windows.Forms.Timer End Class 测试 Dim waitingBox As New FrmWaitingBox(Sub(obj, args) \'耗时操作开始 For i As Integer = 0 To 5 System.Threading.Thread.Sleep(1000) Output.Show(i) Next \'耗时操作结束 End Sub,"正在处理数据,请等待...") waitingBox.ShowDialog() [此贴子已经被作者于2021/6/15 12:06:37编辑过]
|
-- 作者:有点蓝 -- 发布时间:2021/6/15 12:02:00 -- 请上传实例测试 |