A splash screen that checks a database connection

  • Thread starter Thread starter madmabs
  • Start date Start date
M

madmabs

Guest
Hi guys

I just started building an application in Vb.net , that has its splash screen checking to see if a connection can be made to an existing database.

First I created a form titled FrmSplashscreen and in the applications property I set it as the start up form.

Also here is the code in the code editor for FrmSplashscreen

ImportsSystem.Threading


ImportsSystem.Data.SqlClient


 


PublicClassFrmSplashScreen


 


Dimtrd AsThread


ProtectedOverridesSubonload(ByVale AsSystem.EventArgs)


MyBase.OnLoad(e)


DoHeavyDutyStuff_Async()


EndSub


PrivateSubDoHeavyDutyStuff_Async()


'' Start DoHeavyDutyStuff on another thread


' Dim T As New Threading.Thread(AddressOf DoHeavyDutyStuff)


'T.Start()


trd = NewThread(AddressOfDoHeavyDutyStuff)


trd.IsBackground = True


trd.Start()


EndSub


PrivateSubFrmSplashScreen_Load(sender AsObject, e AsEventArgs) HandlesMyBase.Load


 


EndSub


PrivateSubDoHeavyDutyStuff()


'' check for the connection.


'' in this case.


'' and


'' Close the form if connection found

''or entire application if no connection found


UsingCnnWashboxpremiere


Try


CnnWashboxpremiere.Open()

 


MessageBox.Show("Connection OK!")


 


FrmMain.ShowDialog()


 


Catchex AsException


MsgBox(ex.Message.ToString)


MessageBox.Show(" No Connection!")


Application.Exit()


Finally


CnnWashboxpremiere.Close()

 


EndTry


EndUsing


 

 CloseForm()


EndSub


PublicDelegateSubdelCloseForm()


PublicSubCloseForm()




IfMe.InvokeRequired Then


DimD AsNewdelCloseForm(AddressOfCloseForm)


Me.Invoke(D)


 


Exit Sub


 


EndIf


'' Close the form


 


Me.Close()


EndSub


 


EndClass

for the main form Frmain which has menu items here is the code


PrivateSubFrmMain_Load(sender AsSystem.Object, e AsSystem.EventArgs) HandlesMyBase.Load

Me.Bounds = Screen.GetWorkingArea(Me)

EndSub

when no connection can be established the application exits as desired in "DoHeavyDutyStuff()", and if a connection is established the massage box is displayed confirming that, afterwards frmain is displayed but FrmSplashScreen which is supposed to closed/exit according to "CloseForm()" doesn't but remains at the background (behind Frmain), whereas I want it closed or exited. Please can someone point me in the right direction as to what I am doing wrong.


warm regards


Ade

Continue reading...
 
Back
Top