Connecting Tech Pros Worldwide Forums | Help | Site Map

Threading: Showing form in main-thread through different thread

Michael Maes
Guest
 
Posts: n/a
#1: Nov 20 '05
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

Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#2: Nov 20 '05

re: Threading: Showing form in main-thread through different thread


* "Michael Maes" <michael@merlot.com> scripsit:[color=blue]
> 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[/color]

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>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Michael Maes
Guest
 
Posts: n/a
#3: Nov 20 '05

re: Threading: Showing form in main-thread through different thread


Danke Herfried.

Together with a Form.Refresh I managed my goal.

Regards,

Michael


Michael Maes
Guest
 
Posts: n/a
#4: Nov 20 '05

re: Threading: Showing form in main-thread through different thread


Danke Herfried.

Together with a Form.Refresh I managed my goal.

Regards,

Michael


Closed Thread