You can achive your goal in this way.Locked thread is separate one in threadpool and until ti will set manualreset event all code will wait but your ui will not freeze.
Private Sub test1(ByVal obj As Object)
If TypeOf (obj) Is ManualResetEvent Then
Dim _wait = DirectCast(obj, ManualResetEvent)
Thread.Sleep(5000)
_wait.Set()
End If
End Sub
Private Sub TestT_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox("Operation started at " & Now)
Dim h As New List(Of ManualResetEvent)
Dim _wait As New ManualResetEvent(False)
h.Add(_wait)
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf test1), _wait)
WaitHandle.WaitAll(h.ToArray)
MsgBox("Operation completed at " & Now)
End Sub
here in c#(translate with online tools check code)
private void test1(object obj)
{
if ((obj) is ManualResetEvent) {
dynamic _wait = (ManualResetEvent)obj;
Thread.Sleep(5000);
_wait.Set();
}
}
private void TestT_Load(System.Object sender, System.EventArgs e)
{
Interaction.MsgBox("Operation started at " + DateAndTime.Now);
List<ManualResetEvent> h = new List<ManualResetEvent>();
ManualResetEvent _wait = new ManualResetEvent(false);
h.Add(_wait);
ThreadPool.QueueUserWorkItem(new WaitCallback(test1), _wait);
WaitHandle.WaitAll(h.ToArray());
Interaction.MsgBox("Operation completed at " + DateAndTime.Now);
}
however I don't understand why you're blocking for X second your interface....