There is a splash screen that fades in and then in the background some sub procedures are taking place.
Here is the original code; This code gives me cross threading errors dealing with the opacity.
Expand|Select|Wrap|Line Numbers
- Private myDebuglog As DebugLog = ApplicationDebugLog
- Private FormAlpha As Double = 0
- Private WithEvents AlphaTimer As New System.Timers.Timer
- Private WindowsSecurityPrincipal As System.Security.Principal.WindowsPrincipal = New System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent())
- Private ntUserName As String
- Private strt As System.Threading.Thread
- Private Sub frmSplash_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
- ' Fill in the user box
- ntUserName = WindowsSecurityPrincipal.Identity.Name.ToString
- ntUserName = ntUserName.Replace("ILIOSPARTNERS\", "")
- Me.txtLogin.Text = ntUserName
- FormAlpha = 0.0
- Me.Opacity = FormAlpha
- AlphaTimer.Enabled = False
- AlphaTimer.Interval = 10
- AlphaTimer.Enabled = True
- 'strt = New System.Threading.Thread(AddressOf AlphaTimer_Tick(AlphaTimer,)
- End Sub
- Public Sub AlphaTimer_Tick(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles AlphaTimer.Elapsed
- If FormAlpha >= 1 Then
- AlphaTimer.Enabled = False
- Me.Opacity = 1.0
- Else
- Me.Opacity = FormAlpha
- FormAlpha += 0.05
- Me.Refresh()
- End If
- End Sub
- Public Sub UpdateStatus(ByVal status As String)
- lblLoadingStatus.Text = status
- Me.Refresh()
- End Sub
- Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
- Me.Dispose()
- Application.Exit()
- End Sub
So I modified the code to like this thinking this would solve the problem but now I get disposed errors.
here is the revised code;
Expand|Select|Wrap|Line Numbers
- Private myDebuglog As DebugLog = ApplicationDebugLog
- Private FormAlpha As Double = 0
- Private WithEvents AlphaTimer As New System.Timers.Timer
- Private WindowsSecurityPrincipal As System.Security.Principal.WindowsPrincipal = New System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent())
- Private ntUserName As String
- Private strt As System.Threading.Thread
- Private Sub frmSplash_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
- strt = New System.Threading.Thread(AddressOf updateValues)
- strt.Start()
- ' Fill in the user box
- ntUserName = WindowsSecurityPrincipal.Identity.Name.ToString
- ntUserName = ntUserName.Replace("ILIOSPARTNERS\", "")
- Me.txtLogin.Text = ntUserName
- FormAlpha = 0.0
- Me.Opacity = FormAlpha
- AlphaTimer.Enabled = False
- AlphaTimer.Interval = 10
- AlphaTimer.Enabled = True
- 'strt = New System.Threading.Thread(AddressOf AlphaTimer_Tick(AlphaTimer,)
- End Sub
- Public Sub AlphaTimer_Tick(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles AlphaTimer.Elapsed
- updateValues()
- End Sub
- Public Sub updateValues()
- If FormAlpha >= 1 Then
- AlphaTimer.Enabled = False
- changeOpacity()
- 'Me.Opacity = 1.0
- Else
- changeOpacity()
- 'Me.Opacity = FormAlpha
- FormAlpha += 0.05
- Me.Refresh()
- End If
- End Sub
- Public Sub UpdateStatus(ByVal status As String)
- lblLoadingStatus.Text = status
- Me.Refresh()
- End Sub
- Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
- Me.Dispose()
- Application.Exit()
- End Sub
- Public Sub changeOpacity()
- If Me.InvokeRequired Then
- Me.Invoke(New MethodInvoker(AddressOf ChangeOpacity))
- Else
- Me.opacity = FormAlpha
- End If
- End Sub