.net 在代码隐藏中使用SqlDataSource插入它';自己的线程

.net 在代码隐藏中使用SqlDataSource插入它';自己的线程,.net,vb.net,multithreading,.net,Vb.net,Multithreading,我有一个sqldatasource,我需要在插入之前有一个模态弹出窗口,然后有一个模态窗体关闭。我想,如果我在它自己的线程上执行insert,我可以做到这一点。在这种情况下我该怎么做?我查看了它,只找到了使用SQLConnection的示例 Protected Sub CreateAdditionalBatch() '- Do Something before SqlDataSource_ESignCreateFormulation.Insert() '- Do

我有一个
sqldatasource
,我需要在插入之前有一个模态弹出窗口,然后有一个模态窗体关闭。我想,如果我在它自己的线程上执行insert,我可以做到这一点。在这种情况下我该怎么做?我查看了它,只找到了使用SQLConnection的示例

 Protected Sub CreateAdditionalBatch()

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

 end sub
以下是您所做的,在伪代码中,我不记得确切的语法

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
形式上

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

在这段代码中,您调用了一个方法,该方法在打开模态后,将回调传递给do insert时弹出模态窗体。插入完成后,将触发该事件。此事件连接到将关闭窗体的窗体方法。这是伪代码,你需要把它变成现实。这里不需要多线程。

谢谢你的回答。T.S,我会在回家后尝试实现它,如果它有效,我会更新为答案。