Hi Experts,
I am having a ultrawingrid which is used to display the filepaths in column1 and progressbar in column2 i want to import the file from the path (displayed in col1) to the database and while inserting the records i have to show the percentage in progressbar column.. For this purpose i have used Background worker with methodinvokers. It works correctly for 8 out of 10 times. But suddenly its showing an unhandled error and my ultrawingrid is marked with a big 'X' mark.. what may be the problem. i have used try catch too but i cant handle that error...
.
A MethodInvoker does not implicitly invoke execution on the UI thread. You cannot make changes to any controls or the datasource your grid is bound to from anywhere other than the UI thread.
See Control.Invoke on MSDN for more info: http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx
The Following is the place where i am getting this error
Try If (Me.InvokeRequired) Then 'Me.Invoke(New MethodInvoker(AddressOf chk1, i)) Me.Invoke(New MethodInvoker(Function() ' Define a handler for unhandled exceptions for threads behind forms. AddHandler Application.ThreadException, AddressOf MYThreadHandler Try Select Case Me.grdFilesUploadProgress.Rows(UGrow.Index).Cells(0).Value.ToString() Case "BOM Parts List" Me.grdFilesUploadProgress.DisplayLayout.Bands(0).Columns(2).MinValue = 0 'Code to Process BOM Parts List files Dim ObjBOM As New clsImportMachineBOM(intOrganisationId) ObjBOM.DeleteInputMachineBOMData(3) clcmaxval_rows = ObjBOM.FnBulkCopyFromCSVToDB(Me.grdFilesUploadProgress.Rows(UGrow.Index).Cells(1).Value.ToString()) 'Setting the maximum value for the Progressbar If clcmaxval_rows.Count > 0 Then Me.grdFilesUploadProgress.DisplayLayout.Bands(0).Columns(2).MaxValue = clcmaxval_rows(1) intRowsAffcted = clcmaxval_rows(2) End If Me.grdFilesUploadProgress.Rows(UGrow.Index).Cells(2).Value = intRowsAffcted Application.DoEvents() ' ObjBOM = Nothing Case "Production Plan", "Install Base" Me.grdFilesUploadProgress.DisplayLayout.Bands(0).Columns(2).MinValue = 0 Me.grdFilesUploadProgress.DisplayLayout.Bands(0).Columns(2).MaxValue = dtinfotbl.Rows.Count For Each dtrow In dtinfotbl.Rows intProdId = objCommon.GetProductId(dtrow(0), intOrganisationId, 1) 'Code to Process ProductionPlan type of files If Me.grdFilesUploadProgress.Rows(UGrow.Index).Cells(0).Value.ToString() = "Production Plan" Then Dim objProdPlanImport As New clsImportProductionPlan(intOrganisationId, CType(dtrow(1), Integer), CType(dtrow(2).ToString().Trim(), Integer), intProdId, CType(dtrow(3), Integer)) blnresult = objProdPlanImport.fnImportProductionPlan(2) If blnresult = True Then intRowsAffcted += 1 End If Me.grdFilesUploadProgress.Rows(UGrow.Index).Cells(2).Value = intRowsAffcted Application.DoEvents() 'objProdPlanImport = Nothing 'Code to Process Installbase type of files ElseIf Me.grdFilesUploadProgress.Rows(UGrow.Index).Cells(0).Value.ToString() = "Install Base" Then Dim ObjInstallBase As New ClsImportInstallBase(intOrganisationId, intProdId, CType(dtrow(1).ToString(), Integer), CType(dtrow(2).ToString.Trim(), Integer)) blnresult = ObjInstallBase.fnImportInstallBase(2) If blnresult = True Then intRowsAffcted += 1 End If Me.grdFilesUploadProgress.Rows(UGrow.Index).Cells(2).Value = intRowsAffcted Application.DoEvents() 'ObjInstallBase = Nothing End If If blnClosed = True Then End End If Next End Select 'Threading.Thread.Sleep(500) Me.grdFilesUploadProgress.DisplayLayout.Rows(UGrow.Index).Cells(2).Style = ColumnStyle.CheckBox Me.grdFilesUploadProgress.Rows(UGrow.Index).Cells(2).Value = True blnSuccess = True Return Nothing Catch ex As Exception blnSuccess = False fnImportByRow_Ex(UGrow.Index, intRowsAffcted.ToString() & " Row Completed.. Error Loading file. Refer to Log File") Return Nothing End Try End Function)) End If Return blnSuccess Catch ex As Exception Throw ex End Try
Are you able to post the call stack from the exception as well?
This is the error.....
Are you sure you aren't updating any data on a different thread elsewhere in your program?
You can try suppressing the repaint during your update (this is good practice anyhow):
Before the initial Try add (replace '_grid' with the name of your grid):
_grid.BeginUpdate()_grid.SuspendRowSynchronization()
Create a Finally block for the Try/Catch surrounding your entire method and add:
_grid.ResumeRowSynchronization()_grid.EndUpdate()