简体   繁体   中英

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.

How can I get around this?

Thanks in advance.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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