1

I have a sqldatasource and I need to have a modal pop up before the insert, and a modal form to close after. I think, I can do this if I execute the insert on it's own thread. How do I do that in this situation? I looked into it and only found examples using SQLConnection.

 Protected Sub CreateAdditionalBatch()

     '- Do Something before
     SqlDataSource_ESignCreateFormulation.Insert()
     '- Do something after

 end sub

1 Answer 1

1

Here is what you do, in pseudo code, I don't remember exact syntax

private Event InsertCompleted 

sub ThisSubDoesInsert()
    ' insert here . . . . 
    Raise Event InsertCompleted
end sub

Sub ThisSubOpensModal()
    using f as new MyForm(ThisSubDoesInsert) ' may need AdressOf(...)
        AddHandler Me.InsertCompleted, AddressOf f.SubThatWillCloseForm 
        f.ShowModal()
        RemoveHandler Me.InsertCompleted, AddressOf f.SubThatWillCloseForm
    End using
End sub

And in form

class MyForm
    private _callback AS Action ' - set this in constructor

    sub Form_Load
        Me.Show()
        _callback() ' This will call insert
    end sub

    sub SubThatWillCloseForm()
        Me.Close()
    end sub

End Class

In this code, you call a method that pops up the modal form while passing a callback to do insert once modal is open. When insert completes, the event is fired. This event is wired to a form method that will close the form. This is pseudo code, you need to make it real. No need for multi-threading here.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the answer T.S, I will attempt to implement it when I get home and update as answer if it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.