Run a sub from within a tread?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Justin

    #1

    Run a sub from within a tread?

    I'm a newbie to threads. I can run
    "comboProfiles_ SelectedIndexCh anged(sender, e)" from any normal sub in my
    project however if I run this from within a new thread I've started it
    doesn't like "sender" or "e". I know sending info from within a thread is
    different but what I'm doing should be simple so if someone can help me out
    I sure would appreciate it.

    Thanks Much,
    Justin


  • Herfried K. Wagner [MVP]

    #2
    Re: Run a sub from within a tread?

    "Justin" <Justin@NoSpam. com> schrieb:[color=blue]
    > I'm a newbie to threads. I can run
    > "comboProfiles_ SelectedIndexCh anged(sender, e)" from any normal sub in my
    > project however if I run this from within a new thread I've started it
    > doesn't like "sender" or "e". I know sending info from within a thread is
    > different but what I'm doing should be simple so if someone can help me
    > out[/color]

    First, I would rethink if calling an event handler is really the best
    solution.

    Second, don't forget that Windows Forms controls' instance members are not
    safe for multithreading.

    Third, you can use
    'Control.Invoke '/'Control.BeginI nvoke'/'Control.Invoke Required' to call a
    method in the context of the main UI thread from within a secondary thread:

    Multithreading in Windows Forms-Anwendungen
    <URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithread ing&lang=de>

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • Justin

      #3
      Re: Run a sub from within a tread?

      Awesome. Thanks Herfried.


      "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
      news:%2312JIqsX FHA.3860@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > "Justin" <Justin@NoSpam. com> schrieb:[color=green]
      >> I'm a newbie to threads. I can run
      >> "comboProfiles_ SelectedIndexCh anged(sender, e)" from any normal sub in my
      >> project however if I run this from within a new thread I've started it
      >> doesn't like "sender" or "e". I know sending info from within a thread
      >> is different but what I'm doing should be simple so if someone can help
      >> me out[/color]
      >
      > First, I would rethink if calling an event handler is really the best
      > solution.
      >
      > Second, don't forget that Windows Forms controls' instance members are not
      > safe for multithreading.
      >
      > Third, you can use
      > 'Control.Invoke '/'Control.BeginI nvoke'/'Control.Invoke Required' to call a
      > method in the context of the main UI thread from within a secondary
      > thread:
      >
      > Multithreading in Windows Forms-Anwendungen
      > <URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithread ing&lang=de>
      >
      > --
      > M S Herfried K. Wagner
      > M V P <URL:http://dotnet.mvps.org/>
      > V B <URL:http://classicvb.org/petition/>[/color]


      Comment

      Working...