Last active
December 2, 2020 12:44
-
-
Save MakotoUwaya/89f1672ea50d6a6fc1ea9919a89025a6 to your computer and use it in GitHub Desktop.
Tasks UI Invoke Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Public Class Form1 | |
| Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown | |
| Select Case e.KeyCode | |
| Case Keys.F8 | |
| Dim fc As New FormController() | |
| fc.AsyncAction(Me) | |
| End Select | |
| End Sub | |
| End Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Imports System.Threading.Tasks | |
| Public Class FormController | |
| Delegate Sub AddRowDelegate(form As Form1, value As Integer) | |
| Public Sub AsyncAction(form As Form1) | |
| form.DataGridView1.Rows.Clear() | |
| Dim t As New Task(Sub() | |
| For i As Integer = 0 To 19999 Step 1 | |
| form.DataGridView1.Invoke(New AddRowDelegate(AddressOf AddRow), form, i) | |
| Next | |
| End Sub, TaskCreationOptions.PreferFairness) | |
| t.Start() | |
| t.ContinueWith(Sub() MessageBox.Show("Finish!")) | |
| End Sub | |
| Private Sub AddRow(form As Form1, value As Integer) | |
| form.DataGridView1.Invoke( | |
| Sub() | |
| form.DataGridView1.Rows.Add(value + 1, value + 2, value + 3, value + 4, value + 5) | |
| form.DataGridView1.Update() | |
| End Sub) | |
| End Sub | |
| End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment