Link to home
Start Free TrialLog in
Avatar of Amr Aly
Amr AlyFlag for Egypt

asked on

improving performance of my windows App. in VB.Net

I'm new in programming by VB.net ,But actually i've windows App. that i've created it four months ago and now i almost completed and finished it .
How can i improve my application performance .?
When i searched in the web i found an expression called "Threading" but i didn't understand it .
Any suggestions to solve my issue or to guide me to the right way
thanks in advance
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Your question is very broad, and would be difficult to answer without knowing what your application does. Threading can help in some instances, but not all.

Can you explain what your application does?

Do you currently have any areas where you think performance is degraded? If so, why do you think that?
Avatar of Amr Aly

ASKER

Hello Sir ,
I'm pleased to meet you again. Indeed I've VS2015 and Access 2013 with win 8.1(with 4.5 .Net Framework) this is the media of building my App.
But My App. will work on win 7 and 8.1 and 10 . When i run my App. without debugging i notice that there is abnormal issue when moving between combo boxes this is in my first form(i think that it's relatively slow) But it's not the real problem . the problem is when click on the button (responsible for taking the user to the second form and in the second form itself). when click on the grid view the data take many seconds to appear in the text boxes and combo boxes that is in win 8.1 64bit (with or without debugging) .But in win 7 32bit (I installed .Net framework 4.5) you feel that the App. is really slow not slow like a turtle but any one can detect that there is abnormal issue.User generated image
User generated image
It is just impossible to tell you how to improve the speed, there is no magical one-size-fits-all solution.

I would start with database access. Are your queries returns only what is required? And oh you are using Access, not the greatest/fastest tool around!

I would also add tracing to the application (http://emoreau.com/Entries/Articles/2003/11/Code-diagnostic-an-article-on-tracing-and-debugging.aspx). You might discover that some code is executed way to often and thus slowing down the whole thing.
Avatar of Amr Aly

ASKER

I would also add tracing to the application (http://emoreau.com/Entries/Articles/2003/11/Code-diagnostic-an-article-on-tracing-and-debugging.aspx). You might discover that some code is executed way to often and thus slowing down the whole thing.
Hi Éric Moreau,
I've red your article but unfortunately i haven't absorbed it and i didn't know how to use it and how to help me to improve my project.And i downloaded the source code but still have a problem to understand the code and the article.I think that is due to my low experience in programming
My programming age in VB.Net is Four months only ,But i've really a good application(I think so).Really i want to learn and have the ability to that because i'm self-study  and want to be a good programmer
thanks in advance sir
if adding tracing is too much, improving performance is even tougher!
Avatar of Amr Aly

ASKER

I don't know how to adding tracing
I've red your article but unfortunately i haven't absorbed it and i didn't know how to use it and how to help me to improve my project.And i downloaded the source code but still have a problem to understand the code and the article.
Can you tell me in a simple way and in brief without wasting your time how can i do this...?
the very least you can do is to add "Trace.Writeline" in each of your methods/events and check the Output dialog in Visual Studio. By default, the results of the Trace.Writeline is sent there
Avatar of Amr Aly

ASKER

This is your Code for Tracing

Option Strict On

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents btnIndent As System.Windows.Forms.Button
    Friend WithEvents btnFail As System.Windows.Forms.Button
    Friend WithEvents btnWrite As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.btnIndent = New System.Windows.Forms.Button
        Me.btnWrite = New System.Windows.Forms.Button
        Me.btnFail = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(24, 16)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        '
        'btnIndent
        '
        Me.btnIndent.Location = New System.Drawing.Point(32, 80)
        Me.btnIndent.Name = "btnIndent"
        Me.btnIndent.Size = New System.Drawing.Size(200, 23)
        Me.btnIndent.TabIndex = 1
        Me.btnIndent.Text = "Test Indent"
        '
        'btnWrite
        '
        Me.btnWrite.Location = New System.Drawing.Point(32, 48)
        Me.btnWrite.Name = "btnWrite"
        Me.btnWrite.Size = New System.Drawing.Size(200, 23)
        Me.btnWrite.TabIndex = 2
        Me.btnWrite.Text = "Test Write"
        '
        'btnFail
        '
        Me.btnFail.Location = New System.Drawing.Point(32, 112)
        Me.btnFail.Name = "btnFail"
        Me.btnFail.Size = New System.Drawing.Size(200, 23)
        Me.btnFail.TabIndex = 3
        Me.btnFail.Text = "Test Fail"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(264, 182)
        Me.Controls.Add(Me.btnFail)
        Me.Controls.Add(Me.btnWrite)
        Me.Controls.Add(Me.btnIndent)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private mBS As New BooleanSwitch("EricBoolSwitch", "This the Boolean switch.")
    Private mTS As New TraceSwitch("EricTraceSwitch", "This is the Trace switch.")

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Trace.WriteLine("The next line will test the Boolean switch.", Date.Now.ToString)
        Trace.Indent()
        Trace.WriteLineIf(mBS.Enabled, "The Boolean switch is ON.", Date.Now.ToString)
        Trace.Unindent()

        Trace.WriteLine("The 4 following lines will test the Trace switch.")
        Trace.Indent()
        Trace.WriteLineIf(mTS.TraceError, "Written when the switch is set to Error (or greater).")
        Trace.WriteLineIf(mTS.TraceWarning, "Written when the switch is set to Warning (or greater).")
        Trace.WriteLineIf(mTS.TraceInfo, "Written when the switch is set to Info (or greater).")
        Trace.WriteLineIf(mTS.TraceVerbose, "Written when the switch is set to Verbose.")
        Trace.Unindent()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Create a new listener.
        Dim objTL As New TextWriterTraceListener("c:\DemoTrace.log")

        'Remove all existing listeners.
        'Trace.Listeners.Clear()

        'Add the newly created listener to the collection.
        Trace.Listeners.Add(objTL)

        'Adds another listener to the collection.
        Trace.Listeners.Add(New EventLogTraceListener("UTMag - Trace Test"))

        Trace.AutoFlush = True
    End Sub

    Private Sub btnIndent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIndent.Click
        Trace.WriteLine("This message will be written at level 0.")
        Trace.Indent()
        Trace.WriteLine("This message will be written at level 1.")
        Trace.Indent()
        Trace.WriteLine("This message will be written at level 2.")
        Trace.Unindent()
        Trace.Unindent()
        Trace.WriteLine("Back to level 0.")
    End Sub

    Private Sub btnFail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFail.Click
        Trace.Fail("message", "Detailed message")
    End Sub

    Private Sub btnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWrite.Click
        Dim x As Integer = 5

        'The following code outputs: The value of x is = 5
        Trace.Write("The value of x is = ")
        Trace.WriteLine(x)

        'The following code outputs: This is the category: This is the message
        Trace.WriteLine("This is the message", "This is the category")

        'The following code outputs: This message only writes when x=5.
        Trace.WriteLineIf(x = 5, "This message only writes when x=5.")
    End Sub
End Class

Open in new window


Adding ( Trace.WriteLine("") ) like this in the beginning(Before the code in the event or method) or in the end (After code in the event or method)
And how to
check the Output dialog in Visual Studio
Please be Patient with me i want to learn thanks in advance sir.........
Adding ( Trace.WriteLine("") ) like this in the beginning(Before the code in the event or method) or in the end (After code in the event or method)

it would be nice to add it both at the beginning and the end including the time so that way you would discover where time is spent.

to display to output window, see https://msdn.microsoft.com/en-us/library/3hk6fby3.aspx
Avatar of Amr Aly

ASKER

Something Like That Sir
Sub ShowVisDPTable()
        Trace.WriteLine("")
        Using con As New OleDbConnection("provider=microsoft.ace.oledb.12.0; data source=Dr_T.accdb")
            con.Open()

            Using cmd As New OleDbCommand
                cmd.Connection = con
                cmd.CommandText = "SELECT * FROM VisitDP WHERE Visit_no=?"                  '& dgvVisit.CurrentRow.Cells(0).Value
                cmd.Parameters.AddWithValue("@Visit_no", txtVisNo.Text)
                Using dt As New DataTable
                    dt.Load(cmd.ExecuteReader)
                    If dt.Rows.Count > 0 Then
                        txtVisNo.Text = dt.Rows(0).Item("Visit_no")
                        cbxDrug1.Text = dt.Rows(0).Item("NameDrug")
                        cbxPlan1.Text = dt.Rows(0).Item("NamePlan")
                        cbxDrug2.Text = dt.Rows(0).Item("NameDrug1")
                        cbxPlan2.Text = dt.Rows(0).Item("NamePlan1")
                        cbxDrug3.Text = dt.Rows(0).Item("NameDrug2")
                        cbxPlan3.Text = dt.Rows(0).Item("NamePlan2")
                        cbxDrug4.Text = dt.Rows(0).Item("NameDrug3")
                        cbxPlan4.Text = dt.Rows(0).Item("NamePlan3")
                        cbxDrug5.Text = dt.Rows(0).Item("NameDrug4")
                        cbxPlan5.Text = dt.Rows(0).Item("NamePlan4")
                        cbxDrug6.Text = dt.Rows(0).Item("NameDrug5")
                        cbxPlan6.Text = dt.Rows(0).Item("NamePlan5")
                        cbxDrug7.Text = dt.Rows(0).Item("NameDrug6")
                        cbxPlan7.Text = dt.Rows(0).Item("NamePlan6")
                        cbxDrug8.Text = dt.Rows(0).Item("NameDrug7")
                        cbxPlan8.Text = dt.Rows(0).Item("NamePlan7")
                        cbxDrug9.Text = dt.Rows(0).Item("NameDrug8")
                        cbxPlan9.Text = dt.Rows(0).Item("NamePlan8")
                        cbxDrug10.Text = dt.Rows(0).Item("NameDrug9")
                        cbxPlan10.Text = dt.Rows(0).Item("NamePlan9")
                        txtDrug10.Text = dt.Rows(0).Item("NameDrug10")
                        txtPlan10.Text = dt.Rows(0).Item("NamePlan10")
                        txtDrug11.Text = dt.Rows(0).Item("NameDrug11")
                        txtPlan11.Text = dt.Rows(0).Item("NamePlan11")
                        txtDrug12.Text = dt.Rows(0).Item("NameDrug12")
                        txtPlan12.Text = dt.Rows(0).Item("NamePlan12")
                    End If
                End Using
            End Using
        End Using
        Trace.WriteLine("")
    End Sub

Open in new window

yes but you need to put something between the quotes otherwise it is useless!

Trace.WriteLine("ShowVisDPTable started @ " + datetime.now.tostring("yyyy-MM-dd HH:mm:ss"))

Open in new window

Avatar of Amr Aly

ASKER

And if it is in the event i write it like this
  Private Sub cbxInvest3_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles cbxInvest3.Validating
        Trace.WriteLine("cbxInvest3_Validating Started @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
        '' Read the XML file from disk only once
        Dim xDoc = XElement.Load(Application.StartupPath + "\Investigations.xml")
        '' Parse the XML document only once
        Dim cbElements = xDoc.<Invest>.Select(Function(n) n.Value).ToArray()
        If txtVisName.Text <> "" And txtVisPatNo.Text <> "" Then
            btnVisSave_Click(Nothing, Nothing)
            SaveInXmlInv()
            RDXmlInv()
            '' Now fill the ComboBox's 
            cbxInvest4.Items.AddRange(cbElements)
            cbxResult3.Items.AddRange(cbElements)
        End If
        Trace.WriteLine("cbxInvest3_Validating Started @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
    End Sub

Open in new window


Can i write it like this in any event ....?
Trace.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))

Open in new window

sure you can but it will be totally useless. You will see a bunch of time stamps in your Output window without knowing where they are from. Since you want to work on improving performance, you need to know where you lost it!
Avatar of Amr Aly

ASKER

But this code is true when put in every event
Trace.WriteLine("cbxInvest3_Validating Started @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
Trace.WriteLine("cbxInvest_Validating Started @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
Trace.WriteLine("cbxInvest3_Click Started @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
Trace.WriteLine("cbxInvest3_TextChanged Started @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))

Open in new window

Avatar of Amr Aly

ASKER

I'm sorry Mr Éric Moreau , I want learning so please don't be disturbed
not sure to understand. If you add the Writeline as the first line and as the last line of each method (with comment saying STARTED and FINISHED), you will be able to find out which one takes most time or which one is called too many times.
Avatar of Amr Aly

ASKER

OK Sir ,
I've no programming experience ,So i don't know that i have to put at the end of code of each method the word "FINISHED"
Avatar of Amr Aly

ASKER

I think it is like this
 Sub SaveGyn2()
       Trace.WriteLine("SaveGyn2 STARTED @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
        If txtVis.Text = GetAutonumber("Gyn2", "Vis_no") And cbxPatName.Text <> "" Then

            cmd = New OleDbCommand("INSERT INTO Gyn2(Vis_no, Patient_no, GL, Pls, BP," &
                               "Wt, BdBt, ChtH, HdNe, Ext, FunL, Scrs, Edm, US, Amount, AttDt)" &
                               "VALUES(@Vis_no, @Patient_no, @GL, @Pls, @BP, @Wt, @BdBt," &
                               "@ChtH, @HdNe, @Ext, @FunL, @Scrs, @Edm, @US, @Amount, @AttDt)", conn)

            With cmd.Parameters
                .AddWithValue("@Vis_no", txtVis.Text).DbType = DbType.Int32
                .AddWithValue("@Patient_no", txtNo.Text).DbType = DbType.Int32
                .AddWithValue("@GL", cbxGL.Text).DbType = DbType.String
                .AddWithValue("@Pls", cbxPuls.Text).DbType = DbType.String
                .AddWithValue("@BP", cbxBP.Text).DbType = DbType.String
                .AddWithValue("@Wt", cbxWeight.Text).DbType = DbType.String
                .AddWithValue("@BdBt", cbxBP.Text).DbType = DbType.String
                .AddWithValue("@ChtH", cbxChtH.Text).DbType = DbType.String
                .AddWithValue("@HdNe", cbxHdNe.Text).DbType = DbType.String
                .AddWithValue("@Ext", cbxExt.Text).DbType = DbType.String
                .AddWithValue("@FunL", cbxFunL.Text).DbType = DbType.String
                .AddWithValue("@Scrs", cbxScars.Text).DbType = DbType.String
                .AddWithValue("@Edm", cbxEdema.Text).DbType = DbType.String
                .AddWithValue("@US", cbxUS.Text).DbType = DbType.String
                .AddWithValue("@Amount", txtAmount.Text).DbType = DbType.String
                .AddWithValue("@AttDt", DTPickerAtt.Text).DbType = DbType.DateTime

            End With

            If conn.State = ConnectionState.Open Then
                conn.Close()
            End If

            conn.Open()
            cmd.ExecuteNonQuery()
            conn.Close()
        End If
        Trace.WriteLine("SaveGyn2 FINISHED @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
    End Sub

Open in new window

exactly (except that the Finished line needs to have the same name as the started - otherwise you will not be able to relate the start line and the finish line), put these lines in every methods, run your application, and check your Output Window
Avatar of Amr Aly

ASKER

OK sir ,I'll do that and then i'll tell you ,By the way The article of output window is useful thank you
Avatar of Amr Aly

ASKER

Sorry for the delay, I returned back after i've finished the tracing of my second form, Here some photo of output window
I think it will help us to find the damaging codeUser generated imagebtnvisits.png
clickdgv.png
Normal.png
onesecond.png
pressbtnVisits.png
RepeatedThread.png
Thread.png
About the missing PDB, No problem. You're running your code under the debugger, and the debugger is telling you that it doesn't have debugging information for the system libraries. You don't need it as it is a system DLL.

about the 2 seconds between the button click and the new event: any other code in between? It might just be related to the fact the the PowerPacks is loaded (it wasn't before). Why do you use this package?

About the "thread has exited", this is not an error. It is just a normal behavior of the debugger. Multiple threads are generated/used by the debugger.
Avatar of Amr Aly

ASKER

I downloaded and installed this package to use (Print form) but indeed i didn't use it , It's useless because i used the (Print Document) instead.
Is this package slowing down my App. ?
another question please How can we solve this issue ...........sorry sir ?
It is not slowing down your app in general. It is just slowing down the very moment the DLL is loaded in memory just like any other components.

if you don't use it, just remove the reference to it.
Avatar of Amr Aly

ASKER

I removed the reference of it ,but Can you take a look User generated imageUser generated image
You over abuse of the designer database access. This is easing the development but eating up the performance. To give you an idea, I (and most other developers) never use them as you do. It is a shortcut for demo purpose but never in a real application. Most people are using Entity Framework (or another ORM) these days or write a DAL (Data Access Layer) by themselves. But this is a very different and very long topic.

This is surely where your 2 seconds are lost when you load the form. Each DataAdapter/DataSet must be filled.

I also see a Timer there. How frequent is it triggering and what is it doing.
Avatar of Amr Aly

ASKER

To give you an idea, I (and most other developers) never use them as you do. It is a shortcut for demo purpose but never in a real application.
Can i make a new data set and remove these old data sets?
 This is my timers in the two  forms and my database design .....i want your opinion please?

User generated imageUser generated imageUser generated image
what is your timer_tick event doing every second?

I will be of no help for the dataset designer as I don't use them.
Avatar of Amr Aly

ASKER

Timer_Tick for form2, by the way i comment the code in timer _tick below to ensure that if it causes the slowing issue but it doesn't cause the slow performance
 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Trace.WriteLine("Timer1_Ticker STARTED @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
        'If txtVisName.Text <> "" And txtVisNo.Text = GetAutonumber("Visits", "Visit_no") Then
        '    lblcurTime.Text = Now.ToShortDateString
        'ElseIf txtVisName.Text <> "" And txtVisNo.Text <> GetAutonumber("Visits", "Visit_no") Then
        '    'lblcurTime.Text = Now
        '    Exit Sub
        'ElseIf txtVisName.Text = "" And txtVisNo.Text = GetAutonumber("Visits", "Visit_no") Then
        '    lblcurTime.Text = Now.ToShortDateString
        'End If
        lblcurTime.Text = Now
        Trace.WriteLine("Timer1_Ticker FINISHED @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
    End Sub

Open in new window

Timer_Tick for form1
 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        lblcurTime.Text = Now
    End Sub

Open in new window

This Sub responsible for taking the user to the second form
 Sub GotoVisitPH()
        frm2.Show()
        f1.Hide()
        Timer1.Start()

        frm2.ClearData()
        frm2.ClearDrug()
        frm2.txtComplain.Text = "" : frm2.txtSign.Text = "" : frm2.txtDiagnosis.Text = ""
        frm2.txtIntervention.Text = "" : frm2.txtAmount.Text = ""
        frm2.txtVisNo.Text = GetAutonumber("Visits", "Visit_no")
        frm2.txtVisPatNo.Text = txtNo.Text
        frm2.txtVisName.Text = cbxPatName.Text
        'frm2.lblcurTime.Text = Now
        RunCommand("UPDATE Visits Set Name='" & cbxPatName.Text & "' WHERE Patient_no=" & txtNo.Text)
        frm2.Fill_Visits()

Open in new window

I would suspect frm2.Fill_Visits() taking all the time. To prove it, add more tracing:
 Sub GotoVisitPH()
Trace.WriteLine("GotoVisitPH started @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
        frm2.Show()
        f1.Hide()
        Timer1.Start()

        frm2.ClearData()
        frm2.ClearDrug()
        frm2.txtComplain.Text = "" : frm2.txtSign.Text = "" : frm2.txtDiagnosis.Text = ""
        frm2.txtIntervention.Text = "" : frm2.txtAmount.Text = ""
        frm2.txtVisNo.Text = GetAutonumber("Visits", "Visit_no")
        frm2.txtVisPatNo.Text = txtNo.Text
        frm2.txtVisName.Text = cbxPatName.Text
        'frm2.lblcurTime.Text = Now
Trace.WriteLine("GotoVisitPH before RunCommand @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
        RunCommand("UPDATE Visits Set Name='" & cbxPatName.Text & "' WHERE Patient_no=" & txtNo.Text)
Trace.WriteLine("GotoVisitPH before Fill_Visits @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
        frm2.Fill_Visits()
Trace.WriteLine("GotoVisitPH FINISHED @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
end sub

Open in new window

and just for fun, why are you spending your own application performance on showing the time? Windows is already displaying it bottom-right of the screen. Or is it just for debugging?
Avatar of Amr Aly

ASKER

This is what happened in win 7 and win 8.1
win7_1.png
win7_2.png
win7_3.png
win7_4.png
win8.1_1.png
win8.1_2.png
Avatar of Amr Aly

ASKER

and just for fun, why are you spending your own application performance on showing the time? Windows is already displaying it bottom-right of the screen. Or is it just for debugging?
It's not for debugging
Doctors here in Egypt must know the time of their patients visits and in case of the Gynecological  doctors (they have to calculate the period of pregnancy of their patients ) and i saved that in the database
Sorry but I don't see what you mean. I see a gap given apparently by GotoVisitPH but I don't see why. Is it the same network? Wired at the same speed? Database located on the same server? Computers having the same specs (memory, processor speed, ...)? Without having access to your code I just can't do more. I am just blind here!

Maybe it is time for you to consider real tools like https://www.red-gate.com/products/dotnet-development/ants-performance-profiler/index
>>and i saved that in the database

but why every second you are refreshing the time? Just load it once. No need for a timer.
Avatar of Amr Aly

ASKER

but why every second you are refreshing the time? Just load it once. No need for a timer.
I'm not refreshing the time .......oh i see now you talk about (" Timer.Start ") in my first hand in VB.Net (when i needed to open another form i found (on the web) that i have to do this(" me.hide() + form2.show() or from2.showdialog() + Timer.start())  i want to go to the second form with the same name of patient and with the ID number(Patient No) so the timer enable me to do this(i thought so) .
I can upload my whole project in order to feed me by the error and advise me what should i do to solve my issue
Avatar of Amr Aly

ASKER

This is a link of my project without Decrypted Key if you intend to download it tell me to give you the key of decryption
https://mega.nz/#!vtUG0KQS
I will not download the project. I don't work for free.

I have provided you some ways to find where your bottlenecks are and told you that the designer tools to create adapters/datasets shouldn't be used for real applications.
Avatar of Amr Aly

ASKER

OK sir I'm so so sorry
Avatar of Amr Aly

ASKER

Again I'm so so sorry
Thank you sir ,i'm here to learn from experts not to disturb them please accept my apologize
Avatar of Amr Aly

ASKER

but why every second you are refreshing the time? Just load it once. No need for a timer.

I'm not refreshing the time .......oh i see now you talk about (" Timer.Start ") in my first hand in VB.Net (when i needed to open another form i found (on the web) that i have to do this(" me.hide() + form2.show() or from2.showdialog() + Timer.start())  i want to go to the second form with the same name of patient and with the ID number(Patient No) so the timer enable me to do this(i thought so) .


How can i stop refreshing the time.....?
You don't need a timer for that. Just remove it. In your form's Load event, just fill your label:
lblcurTime.Text = Now

Open in new window

Avatar of Amr Aly

ASKER

I really removed (Timer.start) from Visits button()
Sub GotoVisitPH()
        Trace.WriteLine("GotoVisitPH started @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
        frm2.Show()
        f1.Hide()
        '''''''Timer1.Start()

        frm2.ClearData()
        frm2.ClearDrug()
        frm2.txtComplain.Text = "" : frm2.txtSign.Text = "" : frm2.txtDiagnosis.Text = ""
        frm2.txtIntervention.Text = "" : frm2.txtAmount.Text = ""
        frm2.txtVisNo.Text = GetAutonumber("Visits", "Visit_no")
   
        Trace.WriteLine("GotoVisitPH before RunCommand @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
        RunCommand("UPDATE Visits Set Name='" & cbxPatName.Text & "' WHERE Patient_no=" & txtNo.Text)
        Trace.WriteLine("GotoVisitPH before Fill_Visits @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
        frm2.Fill_Visits()
        Trace.WriteLine("GotoVisitPH FINISHED @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
    End Sub

Open in new window

and from Patients button()
 Sub GoToPatients()
        Trace.WriteLine("GoToPatient STARTED @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
        frm1.Show()
        f2.Hide()
        '''''''Timer1.Start()
        frm1.ClearData()
        Trace.WriteLine("GoToPatient FINISHED @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
    End Sub

Open in new window

SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Amr Aly

ASKER

But here something wrong
I need the timer to perform the following task
patient name and patient id go to the second form
after disable the timer (patient name and patient id) don't go to fill the textboxex in the second form
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Amr Aly

ASKER

Sorry Mr Éric Moreau,

How can Form's Shown event would be the right place..?
Form's Shown event of the second form .  GoToVisitPH() put it in this event
Find the right spot for your needs but definitely the timer is not the good one.
Avatar of Amr Aly

ASKER

I think that you put your hand on the main error....you said that " Your issue is surely related to data access".But the question here is
How to fix this issue "DATA ACCESS" ????
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Amr Aly

ASKER

I deleted the table adapter & dataset created by the designer
when i delete the timer i can't enable to go to frm2 as i used to do

User generated image
Public Class frm2

    'Inherits System.Windows.Forms.Form

    Dim conn As New OleDbConnection("provider=microsoft.ace.oledb.12.0; data source=Dr_T.accdb")
    Dim cmd As New OleDbCommand
    Dim da As New OleDbDataAdapter
    Dim da1 As New OleDbDataAdapter
    Dim da2 As New OleDbDataAdapter
    Dim ds As New DataSet
    Dim ds1 As New DataSet
    Dim ds2 As New DataSet
    Dim ds3 As New DataSet
    'Dim dv As New DataView
    'Private BS As New BindingSource
    Dim dt As New DataTable
    Friend f2 As frm2 = Me
    'Friend f1 As New frm1
    'Dim sb As New Text.StringBuilder()

    Public Sub New(S As String, N As String)
        'MyBase.New()
        Trace.WriteLine("New STARTED @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
        'Application.EnableVisualStyles()
        'Application.DoEvents()
        'This call is required by the Windows Form Designer.
        InitializeComponent()
        'Add any initialization after the InitializeComponent() call
        txtVisName.Text = S
        txtVisPatNo.Text = N
        'cmd.Connection = conn

        ds = New DataSet
        da = New OleDbDataAdapter("SELECT * FROM Visits ORDER BY Visit_no", conn)
        da.Fill(ds, "Visits")
        dgvVisit.DataSource = ds.Tables("Visits")
        ''''''''''''''''''''''''''''
        ds1 = New DataSet
        da = New OleDbDataAdapter("SELECT * FROM VisitDP", conn)
        da.Fill(ds1, "VisitDP")
        dgvDrug.DataSource = ds1.Tables("VisitDP")
        '''''''''''''''''''''''''''''''''''
        ds2 = New DataSet
        da = New OleDbDataAdapter("SELECT * FROM Inves", conn)
        da.Fill(ds2, "Inves")
        dgvInv.DataSource = ds2.Tables("Inves")
        ''''''''''''''''''''''''''''
        ds3 = New DataSet
        da = New OleDbDataAdapter("select * from AtFile", conn)
        da.Fill(ds3, "AtFile")
        dgvAtt.DataSource = ds3.Tables("AtFile")
        ''''''''''''''''''''''''''''
        'f2.SuspendLayout()
        'f2.Visible = True
        'f2.ResumeLayout()
        Trace.WriteLine("New FINISHED @ " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
    End Sub

Open in new window

at the top of your form, very first line, add:
Option Strict On

Open in new window

You will get a lot of errors that you will need to fix.
One of them is that your f2 variable is declared into the scope of GotoVisitPH but you use it from within another method (which is incorrect).
Avatar of Amr Aly

ASKER

i changed every thing that you told me and before any imports i put Option Strict On
and the same error .......but f2 didn't appear as a problem
that means that you have another f2 define at a higher scope and when you are in GotoVisitPH, your local copy shadows the one above.
Avatar of Amr Aly

ASKER

You are right
Option Strict On
'Option Explicit On
'Option Infer Off
Imports System.Data.OleDb
Imports System.IO
Imports System.Timers
Imports System.DateTime
Imports System.Xml
Imports System.Management
Imports System.Windows.Forms
Imports System.Configuration
Imports System.Threading
'Imports ExpiryCalc.LicensingUtility

Public Class frm1

    Inherits System.Windows.Forms.Form

    Friend f1 As frm1
    Friend f2 As frm2

Open in new window

What is the right way now
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Amr Aly

ASKER

When i moved this snippet of code out of button visits click the error disappear
  'f2.ShowAttachTable()
             'f2.ShowInvTable()
             'f2.ShowVisitsTable()
             'f2.ShowVisDPTable()

Open in new window

And now i can transfer to form2 but without the (patient name)and(patient id) i think the constuctor doesn't work.But when i put these 2 lines in GoToVisitPH() i can transfer to form2

 
  f2.txtVisPatNo.Text = txtNo.Text
               f2.txtVisName.Text = cbxPatName.Text

Open in new window

so every thing works now? we can finally close this loooooooooong question?
Avatar of Amr Aly

ASKER

OK Sir , I appreciate your efforts and time
I will do Now (As you wish) ......................But you have to know that after modifications in my code my issue is still persist and the slowing issue is more than before
Avatar of Amr Aly

ASKER

I know that is very very very long ......but my nature of my question is required that............  i think so
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Amr Aly

ASKER

Thank you sir you are very respectable man
I really love working with you


Your last comment (I think that is the key)  
many thanks many thanks