RE: Splash Screen..thread safe

2010-02-26 Thread James Chapman-Smith
Hi Anthony,

 

The very first thing you should do is remove the Application.DoEvents()
calls. These are inherently bad and will cause all sorts of concurrency and
threading issues. You can end up with re-entrancy  stack overflows...

 

The best thing is to create the splash screen in its own Application Context
on a different thread. I can dig some code up if you need it.

 

Cheers.

 

James.

 

From: ausdotnet-boun...@lists.codify.com
[mailto:ausdotnet-boun...@lists.codify.com] On Behalf Of Anthony
Sent: Friday, 26 February 2010 13:20
To: 'ausDotNet'
Subject: Splash Screen..thread safe

 

I have created a class to so i can show a splah screen when ever i need to
notify information to the user...works fine but  having issues when i run it
within a thread...how would i make it tread safe?

 

I have  instantiated it within the main form...

 

 

Imports System.Windows.Forms

 

Public Class FormSplash

 

Dim oControl As Control()

Dim oSplash As System.Windows.Forms.Form

 

Sub New()

oSplash = CreateSplash(, )

End Sub

 

Public Sub ShowText(ByVal ParentForm As Form, ByVal sText As String)

oSplash.StartPosition = FormStartPosition.Manual

oSplash.Location = New System.Drawing.Point(ParentForm.Location.X +
((ParentForm.Bounds.Width - oSplash.Width) \ 2), ParentForm.Location.Y +
((ParentForm.Bounds.Height - oSplash.Height) \ 2))

oControl = oSplash.Controls.Find(label1, True)

oControl(0).Text = sText

Application.DoEvents()

oSplash.Show()

Application.DoEvents()

End Sub

 

Public Sub Hide()

oSplash.Hide()

End Sub

 

 

Public Function CreateSplash(ByVal Header As String, ByVal sText As
String) As Form

 

Dim Splash As New Form

Dim label1 As New Label

 

label1 = New System.Windows.Forms.Label()

Splash.SuspendLayout()

' 

' label1

' 

label1.AutoSize = True

label1.Location = New System.Drawing.Point(13, 46)

label1.Name = label1

label1.Size = New System.Drawing.Size(35, 13)

label1.TabIndex = 0

label1.Text = sText

' 

' Splash

' 

Splash.AutoScaleDimensions = New System.Drawing.SizeF(6.0F, 13.0F)

Splash.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font

Splash.ClientSize = New System.Drawing.Size(454, 97)

Splash.ControlBox = False

Splash.Controls.Add(label1)

Splash.MaximizeBox = False

Splash.MinimizeBox = False

Splash.Name = Splash

Splash.Opacity = 1

Splash.ShowIcon = False

Splash.ShowInTaskbar = False

 

Splash.Text = Header

Splash.TopMost = True

Splash.ResumeLayout(False)

Splash.PerformLayout()

 

Return Splash

End Function

 

 

End Class

 

Is your website being http://www.intellixperience.com/signup.aspx
IntelliXperienced?
regards
Anthony (*12QWERNB*)

Is your website being IntelliXperienced?

 

 



RE: Splash Screen..thread safe

2010-02-26 Thread Greg Keogh
Anthony, the sample cs file I sent you shows how to do
Application.Run(formInstance) in a thread. It's surprisingly few lines of
code.

 

Greg



RE: Splash Screen..thread safe

2010-02-25 Thread Keir Nathan
You should use Invoke to open the splash form on the main UI thread.
http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx

Nathan

From: ausdotnet-boun...@lists.codify.com 
[mailto:ausdotnet-boun...@lists.codify.com] On Behalf Of Anthony
Sent: Friday, 26 February 2010 12:50 PM
To: 'ausDotNet'
Subject: Splash Screen..thread safe

I have created a class to so i can show a splah screen when ever i need to 
notify information to the user...works fine but  having issues when i run it 
within a thread...how would i make it tread safe?

I have  instantiated it within the main form...


Imports System.Windows.Forms

Public Class FormSplash

Dim oControl As Control()
Dim oSplash As System.Windows.Forms.Form

Sub New()
oSplash = CreateSplash(, )
End Sub

Public Sub ShowText(ByVal ParentForm As Form, ByVal sText As String)
oSplash.StartPosition = FormStartPosition.Manual
oSplash.Location = New System.Drawing.Point(ParentForm.Location.X + 
((ParentForm.Bounds.Width - oSplash.Width) \ 2), ParentForm.Location.Y + 
((ParentForm.Bounds.Height - oSplash.Height) \ 2))
oControl = oSplash.Controls.Find(label1, True)
oControl(0).Text = sText
Application.DoEvents()
oSplash.Show()
Application.DoEvents()
End Sub

Public Sub Hide()
oSplash.Hide()
End Sub


Public Function CreateSplash(ByVal Header As String, ByVal sText As String) 
As Form

Dim Splash As New Form
Dim label1 As New Label

label1 = New System.Windows.Forms.Label()
Splash.SuspendLayout()
'
' label1
'
label1.AutoSize = True
label1.Location = New System.Drawing.Point(13, 46)
label1.Name = label1
label1.Size = New System.Drawing.Size(35, 13)
label1.TabIndex = 0
label1.Text = sText
'
' Splash
'
Splash.AutoScaleDimensions = New System.Drawing.SizeF(6.0F, 13.0F)
Splash.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Splash.ClientSize = New System.Drawing.Size(454, 97)
Splash.ControlBox = False
Splash.Controls.Add(label1)
Splash.MaximizeBox = False
Splash.MinimizeBox = False
Splash.Name = Splash
Splash.Opacity = 1
Splash.ShowIcon = False
Splash.ShowInTaskbar = False

Splash.Text = Header
Splash.TopMost = True
Splash.ResumeLayout(False)
Splash.PerformLayout()

Return Splash
End Function


End Class

Is your website being 
IntelliXperienced?http://www.intellixperience.com/signup.aspx
regards
Anthony (*12QWERNB*)
Is your website being IntelliXperienced?




RE: Splash Screen..thread safe

2010-02-25 Thread Greg Keogh
Hi Anthony, I've just send you OFFLIST a copy of my splash screen class from
a few years ago. Just in case it might help.

 

The main form creates an instance of the splash class which runs its own
message loop in an STA thread. You can call methods of the class to display
progress messages from the parent form.

 

Cheers,

Greg