Hello friends,
I have developed one application which works perfect but takes 10-15 seconds to load. this is much compare to application.
how do i make it to load fast and i want to show progress i it loads. and i want to load all the controls in the background.
I have 10 textbox's, 1 combobox, 1 picturebox, 6 butttons.
following is the code-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lockfield()
txt_fname.Focus()
btn_updt.Enabled = False
DateTimePicker1.Enabled = False
Dim dt As New DataTable
Try
con.ConnectionString = str
Dim adp1 As New SqlDataAdapter("select rtrim(fname)+' '+rtrim(mname)+' '+rtrim(lname) as [name] from stud", con)
adp1.Fill(ds1, "stud")
dt = ds1.Tables("stud")
Me.ComboBox1.DataSource = dt
Me.ComboBox1.DisplayMember = "name"
Me.ComboBox1.SelectedIndex = 0
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "My Friends")
Finally
End Try
End Sub
this shows data in the fields-
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
clearfields()
ds.Clear()
txt_add.DataBindings.Clear()
txt_email.DataBindings.Clear()
txt_fname.DataBindings.Clear()
txt_lname.DataBindings.Clear()
txt_m1.DataBindings.Clear()
txt_m2.DataBindings.Clear()
txt_mname.DataBindings.Clear()
txt_notes.DataBindings.Clear()
txt_ph1.DataBindings.Clear()
txt_ph2.DataBindings.Clear()
DateTimePicker1.DataBindings.Clear()
Try
con.ConnectionString = str
adp = New SqlDataAdapter("select address,bdate,email,fname,lname,mname,mobile1,mobile2,phone1,phone2,note from stud where rtrim(fname)+' '+rtrim(mname)+' '+rtrim(lname)='" & ComboBox1.Text & "'", con)
adp.Fill(ds, "stud")
dt1 = ds.Tables("stud")
txt_add.DataBindings.Add("Text", ds, "stud.address")
txt_email.DataBindings.Add("Text", ds, "stud.email")
txt_fname.DataBindings.Add("Text", ds, "stud.fname")
txt_lname.DataBindings.Add("Text", ds, "stud.lname")
txt_m1.DataBindings.Add("Text", ds, "stud.mobile1")
txt_m2.DataBindings.Add("Text", ds, "stud.mobile2")
txt_mname.DataBindings.Add("Text", ds, "stud.mname")
txt_notes.DataBindings.Add("Text", ds, "stud.note")
txt_ph1.DataBindings.Add("Text", ds, "stud.phone1")
txt_ph2.DataBindings.Add("Text", ds, "stud.phone2")
DateTimePicker1.DataBindings.Add("Text", ds, "stud.bdate")
Catch ex As Exception
MsgBox(ex.Message)
Finally
End Try
Try
con.ConnectionString = str
con.Open()
Dim cmd As New SqlCommand("select photo from stud where id=(select id from stud where rtrim(fname)+' '+rtrim(mname)+' '+rtrim(lname)='" & ComboBox1.Text & "')", con)
PictureBox1.Image = Image.FromStream(New IO.MemoryStream(CType(cmd.ExecuteScalar, Byte())))
Catch ex As Exception
Finally
con.Close()
End Try
End Sub
When the form loads all controls shows scattered and after 5-10 seconds the're loaded. what i want to do is show loading progress to user and and in the background load the form.
Can you guys tell me how can i do this with background worker/ multithreading?
Thanks.