|
VB.NET • Modify Thread Status Listing 2. A context menu displays when you right-click on an item in the ListView control. These sections of code are executed in response to the Click event of the mnuAbort, mnuSuspend, and mnuResume menu objects. The first item in the SelectedItems property contains the item currently selected. Once the reference is found, the thread's Abort, Suspend, and Resume methods are executed to modify the thread's status. When required, the code verifies the thread's status before any of the methods execute. 'Abort selected thread
Dim item As ListViewItem
Dim ft As FileThread
If lvwThreads.SelectedItems.Count > 0 Then
item = lvwThreads.SelectedItems.Item(0)
ft = Threads.Item(item.SubItems(3).Text)
ft.t.Abort()
ft.t.Join()
End If
'Suspend selected thread
Dim item As ListViewItem
Dim ft As FileThread
If lvwThreads.SelectedItems.Count > 0 Then
item = lvwThreads.SelectedItems.Item(0)
ft = Threads.Item(item.SubItems(3).Text)
If ft.t.ThreadState = ThreadState.Running Then
ft.t.Suspend()
ft.t.Join()
End If
End If
'Resume suspended thread
Dim item As ListViewItem
Dim ft As FileThread
If lvwThreads.SelectedItems.Count > 0 Then
item = lvwThreads.SelectedItems.Item(0)
ft = Threads.Item(item.SubItems(3).Text)
If ft.t.ThreadState = ThreadState.Suspended _
Or ft.t.ThreadState = _
ThreadState.SuspendRequested Then
ft.t.Resume()
End If
End If
|