0

I use a background worker to do some tasks, when the background worker completed successfully a message box appears, the problem I have is if i minimize my form and the message box appears when i click on the form the message boxstill appears to be miminized unless i click on the message box - i can see it in the taskbar at the bottom but its minimized?

Would it be possible for when the user clicks on the form in the taskbar then the message box to appear with the form?

Currently I have tried adding the following before hte message box however the messagebox still appears to be minimized.

me.activate

Update

Sorry for not adding the coding, i thought as it was basic coding it wouldnt matter but here it is....

Private Sub BGWorker_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BGWorker.DoWork


            If Not worker.CancellationPending Then

‘ Do code

                If worker.CancellationPending Then
                    e.Cancel = True
‘ Do Code
                    Exit Sub
                End If

            End If


End Sub


  Private Sub BGWorker_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BGWorker.RunWorkerCompleted
            Me.Activate()
            If e.Cancelled Then
Messagebox.show(“Cancelled”)
            Else
Messagebox.show(“Successful”)

                End If
    End Sub

The problem is if I leave my screen at the top of the other screens then its fine the message box appears however if its minimised ir if i have other windows covering the form then the message box stays minimized unless i click on it in the taskbar.

I thought the me.activate would help me in the sense that the message box would only ever appear within the form.

3
  • Post code that reproduces the problem. Commented Jul 5, 2012 at 14:52
  • A snippet of code is worth a thousand words of explanation... Commented Jul 5, 2012 at 15:46
  • hi guys, have added my coding Commented Jul 6, 2012 at 8:53

1 Answer 1

2

I made a test project using your code and I was able to reproduce and fix the problem. The Activate method does not un-minimize the form. To do that, you need to set the WindowState property. Try this:

Private Sub BGWorker_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BGWorker.RunWorkerCompleted
    Me.WindowState = FormWindowState.Normal  ' Add this line
    Me.Activate()
    If e.Cancelled Then
        Messagebox.show(“Cancelled”)
    Else
        Messagebox.show(“Successful”)

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

3 Comments

Hello Steve, yes the message box appears in the BGWorker Run Worker Completeted event. However I thought the invoke is only required in the do work event?
@JackSparrow Yes, you are right. If you are showing it from the RunWorkerCompleted event, then you don't need to call Invoke. The RunWorkerCompleted event is raised from the UI thread. As Hans has said, it would be helpful if you could post a simplified example of some code that reproduces the problem.
Hi Steve, I will edit my first post to include the coding that I have.

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.