Results 1 to 40 of 62

Thread: VB6 Threading-Examples using the vbRichClient5 ThreadHandler

Threaded View

  1. #2

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 Threading-Examples using the vbRichClient5 ThreadHandler

    The second, more advanced Example resides in the Folder: ThreadedDirScan,
    and covers a "useful real-world-scenario" which fullfills the following requirements:

    - start a (deep, recursive) scanning for Files on the worker-thread, but ensure that:
    - the Main-Thread reflects the current Scan-Results in a List, updating and prolonging it
    - but this List shall in addition remain usable (scrollable, clickable) over the threaded scan-run...
    - this way the Main-Thread can already make use of the (so far) found files from the threaded scan,
    - which will happily proceed undisturbed, without blocking the GUI - until all Files were found

    To make it even a bit harder, the scan shall be used (although usable on all FileTypes)
    primarily to scan for Image-Files, which shall be visualized with a little ThumbNail in
    the List-Control.

    Here is a ScreenShot, how the GUI will look (showing the results of a completed scan,
    but wouldn't look much different whilst a scan is still in progress):



    To accomplish that conveniently, I've made use of primarily three things:
    1) the Event-Support which is available with the RC5-Threading-Helpers
    2) SQLites (InMemoryDB-) FileURIs, which allow working against a shared InMemory-DB across Threads
    3) a Virtual-ListControl, which will render only its currently visible Rows - and has the Data sitting "outside" (in the MemDB)

    The code which is related to 1) is sitting in the cThread-Class of the DirScanThreadLib-ActiveX-Dll-Project
    Code:
    Option Explicit
    
    'two Event-Naming-Conventions, for communication with the vbRichClients hidden cThreadProxy-Class (not reaching the clients, when raised)
    Event CancelCheck(Cancel As Boolean)  'ask the hosting cThreadProxy, whether a client demanded Job-Cancelling
    Event GetFactory(Factory As cFactory) 'ask the cThreadProxy, to deliver a RichClient-Factory-Instance regfree (not used here in this Demo)
    
    'but this is a true User-receivable Event (just define and raise it normally, as any other VB-Event)
    Event ScanProgress(ByVal FilesCount As Long)
    In the Main-Project, the above User-Event (ScanProgress) is received and handled this way:
    Code:
    'and here's the place, where User-Events will be received (when Raised from the Thread-Class)
    Private Sub TH_ThreadEvent(MethodName As String, EventName As String, ByVal ParamCount As Long, P1 As Variant, P2 As Variant, P3 As Variant, P4 As Variant, P5 As Variant, P6 As Variant, P7 As Variant, P8 As Variant)
      If EventName = "ScanProgress" Then FilesCount = P1
    End Sub
    As for Code, related to 2) and 3), I will only show the code-snippet from the Main-Project, which
    is responsible for the refresh of the (Rs-)Data beneath the "sliding-Window" of the virtual ListControl
    (in the appropriate VList_OwnerDrawItem Event):
    Code:
      If Rs Is Nothing Or CurTopIndex <> VList.TopIndex Or CurVisibleRows <> VList.VisibleRows Then
         CurTopIndex = VList.TopIndex
         CurVisibleRows = VList.VisibleRows
         'the Rs is retrieved with only as many Records as needed, to fill the currently "VisibleRows" of the VList (takes only 1 msec or so)
         Set Rs = Cnn.OpenRecordset("Select * From Scan Where ID > " & CurTopIndex & " Limit " & CurVisibleRows + 1)
      End If
    Because that's the part which is perhaps surprising (to consider and undertake at all), since normally
    one wouldn't perform an SQL-request on every single needed "List-Refresh" (as e.g. whilst Scrolling),
    due to "performance considerations"... But an InMemory-DB is a different animal - very responsive
    and "calculatable" in its response-times, because no "potentially blocking or slow HD-Device-IO" will
    interfer when performing Selects against it.

    Just ask, when there are more questions with regards to this example...

    Edit: Here's an additional comment about the ucVList.ctl which is included in the Main-Project...
    It will behave entirely flicker-free only, when the compiled Main-Application was "manifested"
    (with a CommonControls-entry - that's why I've included an appropriate 'manifest.res' in the Project).

    For flickerfree usage in the VB6-IDE itself, VB6.exe could be "manifested" as well... (I'm using
    my VB6-IDE this way since Win7, without larger problems - aside from the "ColorDialogue-issue").

    Olaf
    Last edited by Schmidt; Feb 10th, 2016 at 03:55 AM. Reason: Some additional comments about the ucVList.ctl

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width