Click here to Skip to main content
15,908,906 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Question on how to trap winform closing from VS designer Pin
Аslam Iqbal15-Mar-11 8:11
professionalАslam Iqbal15-Mar-11 8:11 
GeneralRe: Question on how to trap winform closing from VS designer Pin
Jon_Boy15-Mar-11 9:09
Jon_Boy15-Mar-11 9:09 
GeneralRe: Question on how to trap winform closing from VS designer Pin
Mycroft Holmes15-Mar-11 14:14
professionalMycroft Holmes15-Mar-11 14:14 
GeneralRe: Question on how to trap winform closing from VS designer Pin
Jon_Boy16-Mar-11 1:43
Jon_Boy16-Mar-11 1:43 
AnswerRe: Question on how to trap winform closing from VS designer Pin
Luc Pattyn15-Mar-11 4:24
sitebuilderLuc Pattyn15-Mar-11 4:24 
AnswerRe: Question on how to trap winform closing from VS designer Pin
Аslam Iqbal15-Mar-11 8:14
professionalАslam Iqbal15-Mar-11 8:14 
AnswerRe: Question on how to trap winform closing from VS designer Pin
Gregory Gadow15-Mar-11 12:46
Gregory Gadow15-Mar-11 12:46 
QuestionA quick threading question Pin
Alan Burkhart14-Mar-11 19:50
Alan Burkhart14-Mar-11 19:50 
This is my first time building a background thread. It's working but I would really appreciate an opinion or two as to whether I'm doing it the right way. I'll keep it brief as possible:

The app includes a TreeView and ListView, and when a TreeNode is clicked the ListView displays image files from the corresponding directory. I wanted the thumbnail images in the ListView to retain their aspect ratio so I'm drawing a scaled image inside an empty 64x64 thumbnail. If a dir has a lot of large files this can be quite slow.

So, I wrote a sub that gets images for the ListView via ExtractAssociatedIcon to populate the ImageList in the short term, then afterward creates a background thread (MakeThms) to replace the icons in the ListView's ImageList with thumbnails from the original images. The first sub gets the file names and adds the ListViewItems with system icons for the images:
VB
  Private Sub PopulateListView()
   'MakeThms is the name of the thread
    Try
      If MakeThms.IsAlive Then
        MakeThms.Abort() 'stop thread if another TreeNode is clicked while it's running
      End If
    Catch ex As Exception
     'prevent exception if MakeThms is nothing
    End Try

   'code to populate ListView via ExtractAssociatedIcon - omitted for brevity
   
   'then create the thread to make the scaled thumbnails
    Try
      MakeThms = New Thread(AddressOf BuildThumbnails)
      MakeThms.Start()
    Catch ex As Exception
      MsgBox(ex.ToString, MsgBoxStyle.Exclamation, title)
    End Try
  End Sub


'This is the code used by the background thread...
  Private Sub BuildThumbnails()
    For z As Integer = 0 To images.Count - 1 'images is a string collection of the image file names
      '
      '
      'code to create the scaled thumbnails (thm)
      '
      '
   
      'This is the ImageList used by the ListView (lvFiles)
      'Each image in the ImageList is changed as the new thumbnails are created
      imgList.Images(z) = thm
    Next z
    'redraw the ListView once the thumbnails are created
    lvFiles.Invalidate()
  End Sub


I've been testing it for an hour or so and so far no problems. But I'd appreciate any advice if someone sees a potential problem with how I'm getting it done.
Everybody SHUT UP until I finish my coffee...

AnswerRe: A quick threading question Pin
Groulien14-Mar-11 21:28
Groulien14-Mar-11 21:28 
GeneralRe: A quick threading question Pin
Alan Burkhart15-Mar-11 4:52
Alan Burkhart15-Mar-11 4:52 
AnswerRe: A quick threading question Pin
Luc Pattyn15-Mar-11 0:01
sitebuilderLuc Pattyn15-Mar-11 0:01 
GeneralRe: A quick threading question Pin
Alan Burkhart15-Mar-11 4:48
Alan Burkhart15-Mar-11 4:48 
AnswerRe: A quick threading question Pin
Luc Pattyn15-Mar-11 4:53
sitebuilderLuc Pattyn15-Mar-11 4:53 
GeneralRe: A quick threading question Pin
Alan Burkhart15-Mar-11 5:19
Alan Burkhart15-Mar-11 5:19 
AnswerRe: A quick threading question Pin
Luc Pattyn15-Mar-11 5:34
sitebuilderLuc Pattyn15-Mar-11 5:34 
GeneralRe: A quick threading question Pin
Аslam Iqbal15-Mar-11 8:18
professionalАslam Iqbal15-Mar-11 8:18 
QuestionAdo,vb .net datagridview datasource runtime Pin
Member 389234313-Mar-11 23:22
Member 389234313-Mar-11 23:22 
AnswerRe: Ado,vb .net datagridview datasource runtime Pin
Simon_Whale13-Mar-11 23:43
Simon_Whale13-Mar-11 23:43 
GeneralRe: Ado,vb .net datagridview datasource runtime Pin
Dalek Dave14-Mar-11 0:06
professionalDalek Dave14-Mar-11 0:06 
QuestionWriting to debug log Pin
cstrader23213-Mar-11 14:50
cstrader23213-Mar-11 14:50 
AnswerRe: Writing to debug log Pin
Luc Pattyn13-Mar-11 15:04
sitebuilderLuc Pattyn13-Mar-11 15:04 
AnswerRe: Writing to debug log Pin
Bernhard Hiller14-Mar-11 2:26
Bernhard Hiller14-Mar-11 2:26 
QuestionAccess to the registry key is denied. Pin
TornadoApps10-Mar-11 22:24
TornadoApps10-Mar-11 22:24 
AnswerRe: Access to the registry key is denied. Pin
Dalek Dave10-Mar-11 22:40
professionalDalek Dave10-Mar-11 22:40 
GeneralRe: Access to the registry key is denied. Pin
TornadoApps10-Mar-11 22:51
TornadoApps10-Mar-11 22:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.