vb.net多线程打开表单

时间:2018-06-12 10:00:09

标签: vb.net multithreading forms mdiparent

我想创建一个监听器,当它在文件夹中找到文件时,将在MDI中打开一个新表单并删除该文件。但是,表格没有显示出来:

Public Sub CheckFolder()
    Dim th As System.Threading.Thread
    Dim Path As String = "C:/TargetFolder/"
    If (Not System.IO.Directory.Exists(Path)) Then
        System.IO.Directory.CreateDirectory(Path)
    End If
    Do While 1
        Dim di As New DirectoryInfo(Path)
        Dim fiArr As FileInfo() = di.GetFiles()
        Dim fri As FileInfo
        For Each fri In fiArr
            Dim myForm As New frm_Targetfrm
            myForm.MdiParent = frm_MDI
            myForm.txt_ID.Text = fri.Name
            myForm.Show()
            myForm.WindowState = FormWindowState.Normal
            th = New Threading.Thread(Sub() Application.Run(myForm))
            th.Start()
            myForm.Select()
            My.Computer.FileSystem.DeleteFile(Path & fri.Name)
        Next fri
        Threading.Thread.Sleep(500)
    Loop
End Sub

我试图删除用于打开表单的线程并删除代码:

myForm.MdiParent = frm_MDI

它可以打开表单但循环将被停止。有人可以提供更好的主意吗?

非常感谢。

0 个答案:

没有答案