Results 1 to 7 of 7

Thread: Assincronous processes

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Portugal
    Posts
    2

    Question

    Hi everybody! I'm new in VB.

    I want to process SQL store procedure in the SQL server and another VB functions without freezing my terminal.
    When processes a SQL store procedure I can't do nothing until it ends.
    How can I resolve this.

    Thank you!
    dinacio

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    I am afraid this is a little easier said than done.

    First off you will need to create an ActiveX exe project that calls the Stored procedure. And i am afraid it isn't even quite as simple as that.

    You need to call a sub in the AX exe, that starts a timer, and that's it, nothing more. This means that the sub initialises a timer, and passes control back to your VB app.

    When the timer event fires in your AX exe, you call the sub that calls the Stored procedure. This way, the sub is called from the AX exe, and it can run in the background, as control has already been passed back to your VB program.

    Then in your sub that calls the Stored Procedure, you can raise an event back to VB after the work has been done, to let it know that it has done. You can handle this event like any normal event, e.g, click event.

    I hope this has shed some light on the matter.
    Iain, thats with an i by the way!

  3. #3
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    oK, I think I get what you're asking, but you've asked it in a very complicated way.


    By the sound of it you have a procedure that takes a long time to run and when you run it the program freezes until it finishes.

    The answer to this is a Command called DoEvents, what this does is stops the procedure briefly and lets VB handle all the other stuff it needs to do (like repanting the form, allowing the user to move it with the caption bar, letting you click buttons, etc. put the DoEvents command inside any large loops. For Example


    Code:
    Dim i As Integer
    
    For i = 1 To 10000
    
        'Process a record or something that you have to do 10000 times
        Call ProcessRecor(i)
    
    Next i

    will freeze up your app until it finishes, but


    Code:
    Dim i As Integer
    
    For i = 1 To 10000
    
        'Process a record or something that you have to do 10000 times
        Call ProcessRecor(i)
    
        'Allow the App to do anything that needs doing
        DoEvents
    
    Next i

    Won't freeze up your app, hope this helps.

  4. #4
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    lain17

    Lain17...

    That is very goooodd!!

    Have u ever tried that????

    I will soon

    Thanks

  5. #5
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    Guys

    Guys, I found and dowloaded code that does allow this kind of threading with VB

    at

    http://www.vbaccelerator.com/codelib/thread/exethr.htm

    Don't quite understand it yet!!

    Please take a look and if you do understand it...
    share with us...

    I am currently looking at it..

    Thanks

  6. #6
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    ok..me again

    Interesting...
    Usually when I invoke the stored proc...
    until it's completed running... My screen turns unreadable
    and locked

    I just tried sending this

    ls_sqlString = "select count(*) from tblportTable"
    Set rs_me = ExecuteInLineSql(ls_sqlString, m_objConn)

    where m_objConn is an active ADO connection
    rs_me is and ADODB.recordset
    and ExecuteInLineSql is as follows

    Public Function ExecuteInLineSql(ArgString As String, ByRef ArgConnObj As ADODB.Connection) As ADODB.Recordset

    Dim m_objCmd As New ADODB.Command
    Dim rs As New ADODB.Recordset

    On Error GoTo ExecuteInLineSql_EH

    'Set Command Object Properties
    With m_objCmd
    .ActiveConnection = ArgConnObj
    .CommandText = ArgString
    .CommandType = adCmdText

    Set rs = .Execute(, , adAsyncFetchNonBlocking)
    DoEvents
    End With

    'De-ference the Command Object
    Set m_objCmd = Nothing
    Set ExecuteInLineSql = rs
    Set rs = Nothing
    Exit Function

    ExecuteInLineSql_EH:
    Set ExecuteInLineSql = Nothing
    End Function

    Note: the option "adAsyncFetchNonBlocking" with the .execute
    somehow allows me to see everything on the screen
    and apparently it looks like I am not locked?

    Could someone confirm or deny?

  7. #7
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386
    Dan Appleman has written a very intresting article about threading in VB:
    http://www.desaware.com/articles/threadingL3.htm

    if the link doesn't work, it's in the technical articles section, "A Thread To Visual Basic"
    Hope this helps

    Crazy D

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