5 Replies - 1562 Views - Last Post: 18 December 2010 - 04:20 AM Rate Topic: -----

#1 L14M333  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 07-May 10

Opening form into new thread then closing it again from the old thread

Posted 15 December 2010 - 02:05 PM

Hello, I am currently working on a project that has a splashscreen

This splash screen is designed to be shown when the main form begins to load its requirements, and then closes once it has loaded... Currently it works like so:

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        frmSplash.Show()
        dolotsofloading()
        frmSplash.Close()
    End Sub



I was planning to put some form of animation on the splash screen to show that it is actually loading and it hasn't crashed or anything..

Adding the animation to the splash screen does not work correctly however, It will work for about half a second but as the frmMain() is being ran under the same thread, it causes the processes in the splash screen to be frozen while it loads the program...

I have tried various multi threading techniques with no luck :(



I was wondering if anyone knew how I could load the splash screen into a new thread from the frmMain_load sub and then join the thread and close the splash screen again all from the frmMain_load sub...


Any help on this issue would be great!!!


Thanks in advanced


Liam

Is This A Good Question/Topic? 0
  • +

Replies To: Opening form into new thread then closing it again from the old thread

#2 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 147
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Opening form into new thread then closing it again from the old thread

Posted 15 December 2010 - 04:04 PM

Try adding
Application.DoEvents()
every few lines in your loading code.
Was This Post Helpful? 0
  • +
  • -

#3 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1029
  • View blog
  • Posts: 4,008
  • Joined: 02-July 08

Re: Opening form into new thread then closing it again from the old thread

Posted 15 December 2010 - 04:47 PM

1) Designing a form that looks like a Splash Screen,
2) make this the startup form,
3) make a Public Event on the main form you are trying to open, passing a string variable,
4) make another Public Event no parameters, this is our splash form closer,
5) make a different sub for each section of data your loading and in the first line Raise this event, or
if it's one long process just raise this event at diff places with a message to display,
6) open the main form on a new thread from the startup form,
7) use a delegate to route the event (on a diff thread) to the thread where your startup form is
and update a label - showing the progress/process name currently working on the main form,
8) at the end of the form_loading sub raise the closing event,
9) another delegate to route this event, and just call Me.Close in this sub,
10) you can have animated gifs running on the startup form with no issues.

Done!
Was This Post Helpful? 0
  • +
  • -

#4 L14M333  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 07-May 10

Re: Opening form into new thread then closing it again from the old thread

Posted 17 December 2010 - 06:55 AM

thanks for the help however..

hawkvalley1.. I dont fully understand what you mean :S

sorry to be a pain but could you explain a little more :)

also... would your example work if i was to use it at any time (say i clicked a button what had to do a lot of loading)


Thanks

Liam
Was This Post Helpful? 0
  • +
  • -

#5 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1029
  • View blog
  • Posts: 4,008
  • Joined: 02-July 08

Re: Opening form into new thread then closing it again from the old thread

Posted 17 December 2010 - 06:51 PM

Read up on Events, Delegates, and Threading.

The events:
Public Event UpdateProgress(ByVal process As String)
Public Event CloseForm()


During the long process:
RaiseEvent UpdateProgress("something updating!")


At the end of long process:
RaiseEvent CloseForm()


You use the Addhandler on the form that is creating the form with the long form_load process. More tomorrow...

Hawk

This post has been edited by hawkvalley1: 17 December 2010 - 07:27 PM

Was This Post Helpful? 0
  • +
  • -

#6 L14M333  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 07-May 10

Re: Opening form into new thread then closing it again from the old thread

Posted 18 December 2010 - 04:20 AM

View Posthawkvalley1, on 17 December 2010 - 05:51 PM, said:

Read up on Events, Delegates, and Threading.

The events:
Public Event UpdateProgress(ByVal process As String)
Public Event CloseForm()


During the long process:
RaiseEvent UpdateProgress("something updating!")


At the end of long process:
RaiseEvent CloseForm()


You use the Addhandler on the form that is creating the form with the long form_load process. More tomorrow...

Hawk


Thanks.. Ill look into it :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1