Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multithreading question 1

Status
Not open for further replies.

shaminda

Programmer
Jun 9, 2000
170
US
If DataGrid1.InvokeRequired Then
Dim mi2 As New MethodInvoker(AddressOf AddDataGridData)
DataGrid1.Invoke(mi2, Nothing)

Else
DataGrid1.TableStyles.Add(tsGridTableStyles)
End If

Private Sub AddDataGridData(ByVal tsGridTableStyles As DataGridTableStyle)
DataGrid1.TableStyles.Add(tsGridTableStyles)
End Sub


I am getting the following error on line two of the above code

Method ‘Private Sub AddDataGridData(tsGridTableStyles as System.Windows.Forms.DataGridTableStyle)’ does not have the same signature as delegate ‘Delegate Sub MethodInvoker()’

What should I do to fix it? And what am I doing wrong?
 
I'm not familiar with the 'methodinvoker' type. But this should get you a delegate and launch the thread with the proper parameter:

Code:
Private Delegate Sub del_AddDataGridData(ByVal gridTableStyles As DataGridTableStyle)

Private Sub AddDataGridData(ByVal gridTableStyles As DataGridTableStyle)
  If DataGrid1.InvokeRequired Then
    Dim del As New del_AddDataGridData(AddressOf AddDataGridData)
    dim o() as object= {tsGridTableStyles}
    DataGrid1.Invoke(del, o)
  Else
    DataGrid1.TableStyles.Add(gridTableStyles)
  End If
End Sub

You should then be able to call the AddDataGridData method safely from any thread.

Also, on a side note, parameter declarations should not be in hungarian notation. So no type prefixes. I think MS is recommending Camel casing these days instead of Pascal.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top