Foxtable(狐表)用户栏目专家坐堂 → [求助]等待窗口经常卡死


  共有1939人关注过本帖树形打印复制链接

主题:[求助]等待窗口经常卡死

帅哥哟,离线,有人找我吗?
天一生水
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1140 积分:11255 威望:0 精华:0 注册:2017/9/26 16:30:00
[求助]等待窗口经常卡死  发帖心情 Post By: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编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107739 积分:548028 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/6/15 12:02:00 [只看该作者]

请上传实例测试

 回到顶部