Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

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.

Posted

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

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...