generalized thread safe component of windows.form in .NET

Posted on 2012-03-26
Last Modified: 2012-08-13
when used is like this CrossThreadedDbGridView(DataGridView1, "TheText")
   ''//begin cross threaded component
Private Sub dBgRIDvIEWNotInvokeRequired(ByVal dBGridViewcomponentname As DataGridView, ByVal dvalue As String)
    dBGridViewcomponentname.Text = dvalue
End Sub
Private Delegate Sub deldBGrridView(ByVal dBGridViewcomponentname As DataGridView, ByVal dvalue As String)
Private Sub ThreadedDbGridViewAddress(ByVal dBGridViewcomponentname As DataGridView, ByVal dvalue As String)
        If InvokeRequired Then
            Dim udd As New deldBGrridView(AddressOf ThreadedDbGridViewAddress)
            Invoke(udd, New Object() {dBGridViewcomponentname, dvalue})
            dBgRIDvIEWNotInvokeRequired(dBGridViewcomponentname, dvalue)
        End If
    Catch ex As Exception
    End Try
End Sub
Private CrossThreadedDbGridView As New deldBGrridView(AddressOf ThreadedDbGridViewAddress)
''//end cross threaded component

Open in new window

But what if I have lots of member or property to used like this code:
DbGridPapers.ColumnCount = 5
    DbGridPapers.RowCount = rc
    DbGridPapers.Columns(0).HeaderText = "PaperSize"
    DbGridPapers.Columns(1).HeaderText = "#of_Pages"
    DbGridPapers.Columns(2).HeaderText = "#of_Images"
    DbGridPapers.Columns(3).HeaderText = "Payable"
    DbGridPapers.Columns(4).HeaderText = "CountedImage"
    DbGridPapers.Rows(rc).HeaderCell.Value = FileName
    DbGridPapers.Rows(rc).Cells(0).Value = xpapersize
    DbGridPapers.Rows(rc).Cells(1).Value = xpNumbers
    DbGridPapers.Rows(rc).Cells(2).Value = xiNumbers
    DbGridPapers.Rows(rc).Cells(3).Value = xTotImageCounts
    DbGridPapers.Rows(rc).Cells(4).Value = xTotImageCounts

Open in new window

What should I do to make this simple and generally a nice thread safe component
Any ideas? that I can call them like this:
CrossThreadedDbGridView(DataGridView1.ColumnCount, 5)
    CrossThreadedDbGridView(DataGridView1.RowCount, rc)
    CrossThreadedDbGridView(DataGridView1.Columns(0).HeaderText, "PaperSize")

Open in new window

Or is there a better way of doing this, please let me know
Question by:systan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 83

Accepted Solution

CodeCruiser earned 500 total points
ID: 37765127
You can write a utility method which takes the grid name, property name and property value and uses reflection to set value
LVL 14

Author Comment

ID: 37765616
Ok, lets have another simple sample:
''//begin cross threaded TextBox component
    Private Sub TextBoxNotInvokeRequired(ByVal TextBoxcomponentname As TextBox, ByVal dvalue As String)
        TextBoxcomponentname.Text = dvalue
        ''//Dim info As PropertyInfo = TextBoxcomponentname.GetType().GetProperty("")

    End Sub
    Private Delegate Sub delTextBox(ByVal TextBoxcomponentname As TextBox, ByVal dvalue As String)
    Private Sub ThreadedTextBoxAddress(ByVal TextBoxcomponentname As TextBox, ByVal dvalue As String)
            If InvokeRequired Then
                Dim udd As New delTextBox(AddressOf ThreadedTextBoxAddress)
                Invoke(udd, New Object() {TextBoxcomponentname, dvalue})
                TextBoxNotInvokeRequired(TextBoxcomponentname, dvalue)
            End If
        Catch ex As Exception
        End Try
    End Sub
    Private CrossThreadedTextBox As New delTextBox(AddressOf ThreadedTextBoxAddress)
    ''//end cross threaded TextBox component

Open in new window

We can use that with:
CrossThreadedTextBox(Textbox1, "TheText")

But what about if I have this:

I can't write like this:
CrossThreadedTextBox(Textbox1.focus, "")

How is that related to PropertyInfo?
Can you write a short code for that, the focus and select properties

LVL 83

Expert Comment

ID: 37766354
That is not related to property info. None of your code seems to have anything related to focus/select etc.

The basic question, what are you trying to achieve overall?
LVL 14

Author Closing Comment

ID: 37770146
you got the point

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question