Jump to content
Software FX Community

Chart.printer.print - Facing problems running a loop


AsifKhan

Recommended Posts

I have built a small windows application where I have two charts binded to different datatables. I have a command button on the form which issues a print command. everything runs very well as long as the charts are printed once. however, i need to be able to run a loop which will bind the same charts to different datatables (having same schema only different data in them) and print the graphs. In doing so, my application stops responding. the reason why i suspect this has something to do with print command is because i commented the print command and ran my code which ran smoothly and i could see the charts refreshing correctly for each binding command.

I am deallocating the system resources after each iteration and also issuing a sleep command which pauses the application for 5 secs before binding the chart to next datasource.

Please let me know if there is any alternative/more suitable approcah which would solve my problem and allow my application to run the loop without crashing.

Your help will be very much appreciated!

Link to comment
Share on other sites

Another point: the application stops responding at random iterations. sometimes it could run upto 10th iteration whereas in some cases it crashes in the very beginning. In any case, I have so far not been able to run the entire loop without crashing.

(the loop can go upto 200 iterations in this case, with each datasource containing upto 3000 records)

Link to comment
Share on other sites

THE CODE:-

 -------- FOR FIRST CHART --------------

Private Sub bindcharts(ByRef dt1 As DataTable)

Try

Chart1.BringToFront()

Dim title1 As New ChartFX.WinForms.TitleDockable

title1.Text = titletxt

title1.Font = New System.Drawing.Font("Arial", 14.0!)

Chart1.Titles.Clear()

Chart1.Titles.Add(title1)

Chart1.DataSource = dt1

If cmb2.SelectedItem.ToString = "S1" Then

Chart1.Printer.Document.DefaultPageSettings.Landscape =

True

Chart1.Printer.PrintDialog()

Else

Chart1.Printer.Document.DefaultPageSettings.Landscape = True

Chart1.Printer.Print()

End If

Chart1.DataSource = Nothing

dt1.Dispose()

Catch ex As Exception

MsgBox(ex.ToString)

End Try

 

--------- FOR SECOND CHART ---------------------

 

Try

Chart2.BringToFront()

Dim strsql As String = ""Dim dt As New DataTable

Dim pltbarheight As Integer = 0

If rb2.Checked = True Then

dt = clsDBAccess.getResultDataTable(

"MY QUERY GOES HERE WHICH HAS NO ISSUES")

Elsedt = clsDBAccess.getResultDataTable("QUERY")

End IfDim dt7 As New DataTable

Dim drnew As DataRowdt7 = clsDBAccess.getResultDataTable("QUERY")

Dim dr As DataRowDim dtlayers As New DataTable

Dim dc As DataColumndc = New DataColumn("Date", GetType(Date))

dtlayers.Columns.Add(dc)

For Each dr In dt7.Rowsdc = New DataColumn(dr(0), GetType(Integer))

dtlayers.Columns.Add(dc)

Next

' dc = New DataColumn("PLT Survey", GetType(Integer))

' dtlayers.Columns.Add(dc)Dim recdate As DateTime

recdate = DateAdd(DateInterval.Day, -1, dt.Rows(0)(1))

For Each dr In dt.Rows

If dr(1) > recdate Then

drnew = dtlayers.NewRow

drnew(0) = dr(1)

drnew.Item(dr("layer")) = dr("pval")

dtlayers.Rows.Add(drnew)

recdate = dr(1)

Elsedtlayers.Rows(dtlayers.Rows.Count - 1)(dr("layer")) = dr("pval")

End If

NextDim dtPLT As New DataTabledtPLT = clsDBAccess.getResultDataTable("QUERY")

dtlayers.Merge(dtPLT)

Dim dv1 As New DataView(dtlayers)

dv1.Sort =

" Date ASC"

Chart2.DataSource = dv1.Table

Dim title1 As New ChartFX.WinForms.TitleDockable

title1.Text = titletxt

title1.Font = New System.Drawing.Font("Arial", 14.0!)

Chart2.Titles.Clear()

Chart2.Titles.Add(title1)

Chart2.Printer.Document.DefaultPageSettings.Landscape =

True

Chart2.Printer.Print()

Chart2.DataSource =

Nothing

dt.Dispose()

dt7.Dispose()

dtlayers.Dispose()

Catch ex As Exception

MsgBox(ex.ToString)

End Try

 

'--------------------------

THE PIECE OF CODE WHERE I AM CALLING THE ABOVE SUBROUTINES

If

dt.Rows.Count > 0 Then

bindcharts(dt)

Thread.Sleep(5000)

bindlayermeterage(wellid)

Thread.Sleep(5000)

End If
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...