Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. Delegate Method.

Delegate Method.

Scheduled Pinned Locked Moved WCF and WF
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nanda_MR
    wrote on last edited by
    #1

    I am doing a program that completely depend on serial port. While data receiving event I m getting following error. The calling thread cannot access this object because a different thread owns it. for that I used delegate method. Problem solved.

    CP_Text.Dispatcher.Invoke(New DelegateUiText(AddressOf UpdateUiCP))

        Delegate Sub DelegateUiText()
        Private Sub UpdateUiCP()
            CP\_Text.Content = Format(Convert.ToInt32(RxStr.Substring(1, 2), 16) / 100, "0.00") 
        End Sub
    

    But I am using 25 labels and 2 datagrids and 12 textboxs. so i need write above 5 line for all controls so. Is any method, i can handle above error in single method or event? thanks in advance Nanda.

    S 1 Reply Last reply
    0
    • N Nanda_MR

      I am doing a program that completely depend on serial port. While data receiving event I m getting following error. The calling thread cannot access this object because a different thread owns it. for that I used delegate method. Problem solved.

      CP_Text.Dispatcher.Invoke(New DelegateUiText(AddressOf UpdateUiCP))

          Delegate Sub DelegateUiText()
          Private Sub UpdateUiCP()
              CP\_Text.Content = Format(Convert.ToInt32(RxStr.Substring(1, 2), 16) / 100, "0.00") 
          End Sub
      

      But I am using 25 labels and 2 datagrids and 12 textboxs. so i need write above 5 line for all controls so. Is any method, i can handle above error in single method or event? thanks in advance Nanda.

      S Offline
      S Offline
      supercat9
      wrote on last edited by
      #2

      You could reduce the delegate-invoked code to one pair of methods for each property you want to update by doing something like:

      Delegate Sub delSetText(ByVal theControl As Control, ByVal st As String)
      Sub doSetText(ByVal theControl As Control, ByVal st As String)
          theControl.Text = st
      End Sub
      Sub InvokeSetText(ByVal theControl As Control, ByVal st As String)
          theControl.Invoke(New delSetText(AddressOf doSetText), theControl, st)
      End Sub
      

      then to set the text on a happyButton to "George", you would simply say InvokeSetText(happyButton, "George"). Nice and clean and easy.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups