sde Posted March 15, 2004 Posted March 15, 2004 I have a Search() method in my app which runs in its own thread. I want to display a status: "searching..." in the UI while the status is alive, then "complete" when the search is finished and the thread dies. here's how i'm starting the thread: Thread SearchThread = new Thread( new ThreadStart( Search ) ); SearchThread.Name = "Search Thread"; SearchThread.Start(); is there any tutorials anyone knows of that could give an example of how to do this? or maybe even just post the logic here? Quote codenewbie
mocella Posted March 16, 2004 Posted March 16, 2004 If you're doing a synchronous thread, then you can pass you label/progress-bar (whatever) variable into the thread's constructor and store it in some global variable in your thread class. You can update that now local variable to whatever you want and the resulting changes are seen in your form. Let me know if you want more detail. Quote
Tryster Posted March 16, 2004 Posted March 16, 2004 I think you'd find it easier to declare a delegate, and fire the process off on a thread allocated from the thread pool: Private Delegate Sub RunProcessDelegate() Private Sub StartProcessRunning() Dim oDel As New RunProcessDelegate(AddressOf RunProcess) Dim oCallback As New AsyncCallback(AddressOf ProcessFinished) oDel.BeginInvoke(oCallback, Nothing) End Sub Private Sub RunProcess() 'This method will be called on a different thread and will run asynchronously End Sub Private Sub ProcessFinished(ByVal ar As IAsyncResult) If ar.IsCompleted Then MessageBox.Show("Process finished asynchronously!") End If End Sub Quote
mocella Posted March 16, 2004 Posted March 16, 2004 Good idea - I had actually done something like that recently but had also done it the other way I suggested a while back. Probably easier to use the callback. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.