locked
how to rectify A shared violation occured in vb2008 RRS feed

  • Question

  • hai all

    how to rectify A shared violation occured in vb2008

                                                                by ilai

    Monday, October 29, 2012 8:41 AM

All replies

  • Hi Ilai,

    Welcome to the MSDN forum.

    Could you please provide information about when and how you receive this message?

    Thanks,


    Shanks Zen
    MSDN Community Support | Feedback to us

    Tuesday, October 30, 2012 2:54 AM
    Moderator
  • .......................

             im creating chart using excel..first i selected value will show the chart ..next i selected second value that time will occured error 'A shared violation occured ' how i can rectify this error ..

    'below the codes

    xlWrkSheet.Cells(2, 1) =

    "Sessn1"

    xlWrkSheet.Cells(3, 1) =

    "sessn2"

    xlWrkSheet.Cells(4, 1) =

    "sessn3"

    xlWrkSheet.Cells(5, 1) =

    "sessn4"

    xlWrkSheet.Cells(6, 1) =

    "sessn5"

    xlWrkSheet.Cells(7, 1) =

    "sessn6"

    For i = 0 To DGV1.RowCount - 2

    For j = 0 To DGV1.ColumnCount - 1

    xlWrkSheet.Cells(i + 2, j + 2) = _

    DGV1(j, i).Value.ToString()

    Next

    Next

    'create chart

    xlApp.Workbooks.Add()

    xlApp.Worksheets.Add()

    xlApp.Charts.Add()

    'create chart

    xlCharts = xlWrkSheet.ChartObjects

    myChart = xlCharts.Add(10, 80, 300, 250)

    xlchartPage = myChart.Chart

    xlchartRange = xlWrkSheet.Range(

    "A1", "d5")

    xlchartPage.SetSourceData(Source:=xlchartRange)

    xlchartPage.ChartType = Excel.XlChartType.xlColumnClustered

    xlchartPage.ChartType = Excel.XlChartType.xlColumnClustered

    'exporting chart as picture file

    xlWrkSheet.ChartObjects(1).chart.Export(FileName:= _

    "D:\excel_chart_export.bmp", FilterName:="BMP")

    'load the pipcture into the picture box

    PictureBox1.Image =

    New System.Drawing.Bitmap _

    (

    "D:\excel_chart_export.bmp")

    Tuesday, October 30, 2012 4:52 AM
  • Hi Ms.Ilai,

    Thanks for your clarify. Could you please show us that which line of code that thrown?  Seems the exception was thrown when you export and load the same file excel_chart_export.bmp. I would suggest check if the bmp file was disposed before loading.

    If I misunderstood anything, please feel free to let me know.

    Best regards,


    Shanks Zen
    MSDN Community Support | Feedback to us

    Tuesday, October 30, 2012 9:36 AM
    Moderator
  • Thanks for reply

                         

    'exporting chart as picture file

    xlWrkSheet.ChartObjects(1).chart.Export(FileName:= _

    "D:\excel_chart_export.bmp", FilterName:="BMP")

    .This line code will occur that error                                                                      

    Wednesday, October 31, 2012 9:57 AM
  • Hi Ms.Ilai,

    I would suggest you ensure the .bmp file was exported completely before load it to picturebox. This may cause shared voilation error.

    Best regards,


    Shanks Zen
    MSDN Community Support | Feedback to us

    Friday, November 9, 2012 10:15 AM
    Moderator