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. WPF
  4. Invoke WPF

Invoke WPF

Scheduled Pinned Locked Moved WPF
csharpwpfhelpquestion
3 Posts 2 Posters 8 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.
  • G Offline
    G Offline
    geomeo123
    wrote on last edited by
    #1

    I have some code I'm trying to move to my view model. And it appears that my Invoke method does not work in it. I have the following code...

    public delegate void SetTextCallBackSMT(string text);

    Handing my serial port

    string SMTData = SpSMT.ReadExisting();
    if (SMTData.Contains("\r"))
    {
    modeSMT = ModeSMT.readLineSMTData;
    }
    else
    {

    Invoke(new SetTextCallBackSMT(SetTextSMTDisplay), SMTData.ToString());
    

    }

    And my set text method....

    private void SetTextSMTDisplay(string text)
    {
    this.RichTextBoxSMTDisplay.Text += text;
    }

    The problem I'm having is that Invoke does not exist in the current context. I've tried adding forms name space. I've tried Dispatcher.Invoke, but I can't get that to work either. Any ideas?

    R 1 Reply Last reply
    0
    • G geomeo123

      I have some code I'm trying to move to my view model. And it appears that my Invoke method does not work in it. I have the following code...

      public delegate void SetTextCallBackSMT(string text);

      Handing my serial port

      string SMTData = SpSMT.ReadExisting();
      if (SMTData.Contains("\r"))
      {
      modeSMT = ModeSMT.readLineSMTData;
      }
      else
      {

      Invoke(new SetTextCallBackSMT(SetTextSMTDisplay), SMTData.ToString());
      

      }

      And my set text method....

      private void SetTextSMTDisplay(string text)
      {
      this.RichTextBoxSMTDisplay.Text += text;
      }

      The problem I'm having is that Invoke does not exist in the current context. I've tried adding forms name space. I've tried Dispatcher.Invoke, but I can't get that to work either. Any ideas?

      R Offline
      R Offline
      Richard Deeming
      wrote on last edited by
      #2

      Most code in the view-model doesn't need to worry about threading issues. The binding to the view will usually take care of that for you. The only exception I'm aware of is if you're updating a collection from a background thread, where you may need to call the BindingOperations.EnableCollectionSynchronization[^] method to get it to work properly.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      G 1 Reply Last reply
      0
      • R Richard Deeming

        Most code in the view-model doesn't need to worry about threading issues. The binding to the view will usually take care of that for you. The only exception I'm aware of is if you're updating a collection from a background thread, where you may need to call the BindingOperations.EnableCollectionSynchronization[^] method to get it to work properly.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        G Offline
        G Offline
        geomeo123
        wrote on last edited by
        #3

        This is extremely helpful to know! Thanks!

        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