Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 25th, 2004, 06:12 AM
Registered User
 
Join Date: Aug 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to nugie73 Send a message via Yahoo to nugie73
Default Windows Form Threading Problem

Hi everybody,

I have been developing a VB.NET application using DirectX to display various multimedia within a screen (windows.form). The application displays consecutive screens based on user-defined schedule. In order to fully load the next screen in the background, so that it makes transition between screens going smoothly, I am using Threading technique. However, the screen never appears, in contrast it works fine when I do not use the Threading, but the next screen never loaded properly (some directX components cannot be loaded) and transition does not go smoothly.

Here it is my source code:

Dim ShowFormThread As Thread
Friend WithEvents tm As New System.Windows.Forms.Timer

'frmCanvas is a class inherits from System.Windows.Forms.Form
Friend WithEvents RunForm, OldForm As frmCanvas

Private Sub TickMe()
   'timer to trigger this module
   tm.Enabled = False

   'assign the current/running screen (RunForm) into OldForm
   OldForm = RunForm

   'call module that assign RunForm into the next screen
   'also assign next interval timer
   LoopFunc()

   'keep the running screen (OldForm) runs at front
   If Not OldForm Is Nothing Then
      OldForm.BringToFront()
   End If

   If RunForm Is Nothing Then
      tm.Enabled = False
      tm.Stop()
      Me.Close()
      Process.GetCurrentProcess.Kill()
      Exit Sub
   End If

   'this commented part to show the next screen if i do not use Thread method
   '''RunForm.WindowState = FormWindowState.Minimized
   '''RunForm.Opacity = 1
   '''RunForm.Visible = False
   '''RunForm.SendToBack()
   '''RunForm.Show()
   '''RunForm.SendToBack()
   '''RunForm.Visible = True
   '''RunForm.WindowState = FormWindowState.Maximized
   '''RunForm.Location = New System.Drawing.Point(0, 0)

   'if start the first screen, i do not use Thread method
   If blnStartPlay Then
      Call ShowForm()
      blnStartPlay = False
   Else
   'second screen onwards, i use Thread method
      If Not ShowFormThread Is Nothing Then
         If ShowFormThread.IsAlive Then
            ShowFormThread.Abort()
            ShowFormThread = Nothing
         End If
      End If

      ShowFormThread = New Thread(AddressOf ShowForm)
      ShowFormThread.Start()

      'make sure the thread of next screen stop, it means letting the next screen
      'fully loaded at background
      If ShowFormThread.IsAlive Then
         While ShowFormThread.IsAlive
         End While
      End If
   End If

   If Not OldForm Is Nothing Then
      'make the current/running form (OldForm) moving to right as horizontal transition
      Call HorizontalTransition(OldForm.Width)

      RunForm.BringToFront()

      Dim z As Double
      For z = OldForm.Controls.Count - 1 To 0 Step -1
          OldForm.Controls(z).Dispose()
      Next

      OldForm.MainFrm = Nothing
      OldForm.Dispose()
      OldForm = Nothing
   End If

   GC.Collect()

   If Not Running Then
      tm.Stop()
      tm.Enabled = False
   End If

   Thread.Sleep(1000)

   tm.Enabled = True
End Sub

Private Sub tm_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tm.Tick
   TickMe()
End Sub

Private Sub HorizontalTransition(ByVal intWidth As Integer)
   Dim intTransition As Integer

   For intTransition = 0 To intWidth Step 100
       OldForm.Location = New System.Drawing.Point(intTransition, 0)
   Next

   Exit Sub
End Sub

Private Sub ShowForm()
   RunForm.WindowState = FormWindowState.Minimized
   RunForm.Opacity = 1
   RunForm.SendToBack()
   RunForm.Show()
   RunForm.SendToBack()
   RunForm.WindowState = FormWindowState.Maximized
   RunForm.Location = New System.Drawing.Point(0, 0)

   Exit Sub
End Sub

The RunForm at the second screen onwards never appear after I call it using Thread method via method ShowForm.

Please help me on this problem. Thanks a lot in advance.

cheers,
nugie73





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch.14 Creating Windows Form User Controls problem SAIFI BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7 1 September 29th, 2008 05:51 AM
Windows Form Problem Ashish Kukreja C# 1 October 6th, 2007 04:15 PM
Windows Forms Threading julesmel C# 3 October 5th, 2006 05:21 AM
System.Threading timer problem for beginner (Windo erikmail C# 2005 1 June 8th, 2006 08:03 AM
ATL Com Dll :problem in threading eternalme Visual C++ 0 April 20th, 2004 12:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.