title: Avoid using this.Invoke(..) on an event handler in c# compact framework
body: <p>I’m using a separate class that instantiates different barcode objects depending on the type of machine, which raise events once a barcode is read.</p>
  
  <p>So to transmit it to the form, I also raise an UNIQUE event ‘myEvent’ that all my forms listens, but inside the form I have to use this.Invoke((Action) mymethod(argument)); to be able to update the components at the user interface, as long as the handler to myEvent is executed on another thread different from that of the form.</p>
  
  <p>So I have this:</p>
  
  <p>My class -> barcode.readed(..) is triggered, then from its handler, I Raise myEvent, that is captured on my Form, and from the handler for myEvent on my form, I execute the this.Invoke…</p>
  
  <p>I know this is a somewhat standard procedure, but I’d like to get rid of that Invoke, and instead, calling directly to the myMethod(argument); function.</p>
  
  <p>I think that this is related to make my class thread safe, but I don’t know how to implement that in my case.</p>
  
  <p>In fact, if I use the original manufacturer barcode.readed() event from inside the form it does not need to call the invoke, as long as this is thread safe, but I don’t know how to mimic that, and I really need to wrap all the different barcode handlers inside a different project, for my forms to use only one ‘myEvent’ that returns the desired barcode, and thus, not repeating code.</p>
  
  <p>Thanks in advance,</p>
  
  <p>Roger Tranchez</p>