简体   繁体   English

Visual Basic VB.Net-GUI暂停复选框

[英]Visual Basic VB.Net - GUI Pause Checkbox

I'm attempting to create a checkbox that will pause the current function when clicked. 我试图创建一个复选框,单击该复选框将暂停当前功能。 Here's how my code is set up- 这是我的代码设置方式-

Public Function Wait()
    LogOutput("Application paused.")
    Do Until waitBox.Checked = False
        'Task.Delay(1000)
        My.Application.DoEvents()
    Loop
    LogOutput("Application unpaused.")
Return Nothing
End Function

Public Function Thing()
   For Each i In x
      If waitBox.Checked Then
          Wait()
      Else
          DoStuff()
      End If
   Loop
Return Nothing
End Function

As you can see I've tried "Task.Delay" as well as "DoEvents(), however the problem is that the GUI is locked up while the function is running and so the user is unable to click pause at all. 如您所见,我已经尝试了“ Task.Delay”和“ DoEvents()”,但是问题是该函数运行时GUI被锁定,因此用户根本无法单击暂停。

How can I get around this? 我该如何解决?

Thanks in advance. 提前致谢。

您需要为此创建一个新线程,因此GUI不会被锁定: https : //msdn.microsoft.com/zh-cn/library/system.threading.thread(v=vs.110).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM