Results 1 to 3 of 3

Thread: Asnychronous Processing..

  1. #1

    Thread Starter
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496

    Asnychronous Processing..

    I'm developing an Out-of Process COM Server, and I'm trying to get my asynchronous calls to work. Right now, I'm just testing various examples to get the feel for it..For Example:

    ActiveX EXE (Code)



    Code:
    Public Event MsgMessage()
    
    Public Sub AsncExample()
        For X = 1 to 30000
            DoEvents()
        Next X
        RaiseEvent MsgMessage
    End Sub

    COM Client (Standard EXE)

    Code:
    Dim WithEvents oAsnc As CExample
    
    Private cmdClick_click()
        Set oAsnc = New CExample
        Call oAsnc.AsncExample
    End Sub
    
    Private oAsnc_MsgMessage()   '// This may or not be the right definition.  I just free-handed this    
        MsgBox "Event Fired!"
    End Sub

    Now, on my standard exe, I have a text box, and when I call the COM's method, I am unable to type in the textbox. What am I missing?? Thanks All'

  2. #2
    Junior Member robinm's Avatar
    Join Date
    May 2001
    Location
    London
    Posts
    19

    Out of Process Server

    The problem is that you are having to wait for the process to finish.
    I do something similar with an out of process exe.
    Put the following into a .bas file int the project.
    Also I have tried to attach runnable.tlb file you need to register,
    the system willnot let me. Mail me at [email protected] and I will mail it back to you.
    This will give you the out of process effect you get in Java.


    Option Explicit

    ' ==============================================================
    ' FileName: mStart.bas
    ' Author: SP McMahon
    ' Date: 2 February 2000
    '
    ' This BAs module gives you the code you need to implement the
    ' Java out-of-process style threading model in VB. Just
    ' add it to an ActiveX EXE, reference Runnable.TLB and then
    ' do this in your ActiveX EXE:
    '
    ' Implements Runnable
    '
    ' Public Sub Start()
    ' mStart.Start Me
    ' End Sub
    '
    ' Private Sub IRunnable_Start()
    ' ' Do your code here. It will run async against
    ' ' the calling app.
    ' End Sub
    '
    '
    ' based on the Codeflow sample © 1997 Microsoft
    ' from Microsoft. Microsoft has no warranty,
    ' obligations or liability for any code used here.
    '
    ' ==============================================================


    ' To prevent object going out of scope whilst the timer fires:
    Private Declare Function CoLockObjectExternal Lib "ole32" (ByVal pUnk As IUnknown, ByVal fLock As Long, ByVal fLastUnlockReleases As Long) As Long

    ' Timer API:
    Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long

    ' Collection of Runnable items to start:
    Private m_colRunnables As Collection
    ' The ID of our API Timer:
    Private m_lTimerID As Long

    Private Sub TimerProc(ByVal lHwnd As Long, ByVal lMsg As Long, ByVal lTimerID As Long, ByVal lTime As Long)
    Dim this As Runnable
    ' Enumerate through the collection, firing the
    ' Runnable_Start method for each item in it and
    ' releasing our extra lock on the object:
    With m_colRunnables
    Do While .Count > 0
    Set this = .Item(1)
    .Remove 1
    this.Start
    'Ask the system to release its lock on the object
    CoLockObjectExternal this, 0, 1
    Loop
    End With
    ' Remove the timer:
    KillTimer 0, lTimerID
    m_lTimerID = 0
    End Sub

    Public Sub Start(this As Runnable)
    ' Ask the system to lock the object so that
    ' it will still perform its work even if it
    ' is released
    CoLockObjectExternal this, 1, 1
    ' Add this to runnables:
    If m_colRunnables Is Nothing Then
    Set m_colRunnables = New Collection
    End If
    m_colRunnables.Add this
    ' Create a timer to start running the object:
    If Not m_lTimerID Then
    m_lTimerID = SetTimer(0, 0, 1, AddressOf TimerProc)
    End If
    End Sub
    To imitate is human... to copy without recognition is theft.

  3. #3
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    Hi,

    You can call a sub in the ActiveX.exe that initalizes a timer. Using set and kill timer APIs or a regular timer object on a form. From the timer event call the processing function in your ActiveX.exe. The thread from the timer will be owned by the AcitveX.exe, and the thread that initalized the ActiveX object will return to the regular exe.

    That which does not kill us, only makes us stronger.

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