Threading: Showing form in main-thread through different thread

M

Michael Maes

Hello,

I know forms aren't thread-safe, but I'm a bit stuck here....

I have an MDI-Application which after 'Login' loads the Data from an SQL Server into DataSets.
Those DataSets are Parented on a "DataForm" which is loaded like this:
If IsNothing(Data) Then

Data = New frmData

MDI.containerData.Controls.Add(Data) (MDI = MDI-Container)

With Data

..Dock = DockStyle.Fill

..Show()

End With

End If


The frmData has
Me.SetTopLevel(False)

.... So it's not an MDI-Child ...

In the Load-Event a Thread (trdData) is created to retreive the Data from the server.
After all the data has been loaded (still trdData) an instance is created of a popup-form to alert the user the Data has been loaded.
Dim pop As popMessage = New popMessage

pop.Show("Message")

As you can see the Show-Method of the Form popMessage has been overloaded (to pass the message to display)

What happens is the popMessage gets displayed for about 0,05 seconds and disappears then.
I think the "Invoke-Method" should be called, but I can 't figure-out how

You might be thinking why I'm not using a msgbox... well the popMessage is like the pop-up Outlook 2003 has (together with the background & fading)


Any suggestions would be more then welcome.

TIA,

Michael
 
H

Herfried K. Wagner [MVP]

* "Michael Maes said:
In the Load-Event a Thread (trdData) is created to retreive the Data from the server.

After all the data has been loaded (still trdData) an instance is created of a popup-form to alert the user the Data has been
loaded.

Dim pop As popMessage = New popMessage

pop.Show("Message")

As you can see the Show-Method of the Form popMessage has been overloaded (to pass the message to display)

 

What happens is the popMessage gets displayed for about 0,05 seconds and disappears then.

I think the "Invoke-Method" should be called, but I can 't figure-out how

You can, for example, add a public method to one of your forms, and then
use the form's 'Invoke' method to call the message form. You will find
some resources and samples on multithreaded UIs there:

<URL:http://msdn.microsoft.com/library/en-us/dnforms/html/winforms06112002.asp>
<URL:http://msdn.microsoft.com/library/en-us/dnforms/html/winforms08162002.asp>
<URL:http://msdn.microsoft.com/library/en-us/dnforms/html/winforms01232003.asp>
 
M

Michael Maes

Danke Herfried.

Together with a Form.Refresh I managed my goal.

Regards,

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top