.NET EVents & Threading

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

    #1

    .NET EVents & Threading

    Hi all


    When .NET fires and event, does the event handler execute under a new
    thread, or does it execute under the primary application thread?

    Basically if I have events firing, do the event handlers themselves need to
    spawn need threads, or can I safely assume the event handler is already
    running under a new thread?

    Thanks!
  • Armin Zingler

    #2
    Re: .NET EVents & Threading

    "Spam Catcher" <spamhoneypot@r ogers.comschrie b
    Hi all
    >
    >
    When .NET fires and event, does the event handler execute under a
    new thread, or does it execute under the primary application thread?
    The event handler runs in the same thread as the code that raises the event.
    No thread is created. The event handler is just a function called.
    Basically if I have events firing, do the event handlers themselves
    need to spawn need threads, or can I safely assume the event handler
    is already running under a new thread?
    If you want to run something in a new thread each time the event handler is
    called, you must start the thread on you own.


    Armin

    Comment

    • Spam Catcher

      #3
      Re: .NET EVents &amp; Threading

      "Armin Zingler" <az.nospam@free net.dewrote in
      news:uiUXtBgVHH A.4720@TK2MSFTN GP04.phx.gbl:
      The event handler runs in the same thread as the code that raises the
      event. No thread is created. The event handler is just a function
      called.
      >
      >Basically if I have events firing, do the event handlers themselves
      >need to spawn need threads, or can I safely assume the event handler
      >is already running under a new thread?
      >
      If you want to run something in a new thread each time the event
      handler is called, you must start the thread on you own.
      Thank you - That clears it up :-)

      Comment

      • Tom Shelton

        #4
        Re: .NET EVents &amp; Threading

        On Feb 21, 2:36 pm, "Armin Zingler" <az.nos...@free net.dewrote:
        "Spam Catcher" <spamhoney...@r ogers.comschrie b
        >
        Hi all
        >
        When .NET fires and event, does the event handler execute under a
        new thread, or does it execute under the primary application thread?
        >
        The event handler runs in the same thread as the code that raises the event.
        No thread is created. The event handler is just a function called.
        >
        Basically if I have events firing, do the event handlers themselves
        need to spawn need threads, or can I safely assume the event handler
        is already running under a new thread?
        >
        If you want to run something in a new thread each time the event handler is
        called, you must start the thread on you own.
        >
        Armin

        Or run the delegate asycronously using BeginInvoke - in that case, the
        method will be called on a thread from the thread pool.

        --
        Tom Shelton

        Comment

        • Spam Catcher

          #5
          Re: .NET EVents &amp; Threading

          "Tom Shelton" <tom_shelton@co mcast.netwrote in
          news:1172094489 .837789.178250@ q2g2000cwa.goog legroups.com:
          Or run the delegate asycronously using BeginInvoke - in that case, the
          method will be called on a thread from the thread pool.
          If I do so, I'll have to call EndInvoke correct?

          I'm using Threadpool.Queu eUserWorkItem to process each call in it's own
          thread.

          Comment

          • Tom Shelton

            #6
            Re: .NET EVents &amp; Threading

            On 2007-02-21, Spam Catcher <spamhoneypot@r ogers.comwrote:
            "Tom Shelton" <tom_shelton@co mcast.netwrote in
            news:1172094489 .837789.178250@ q2g2000cwa.goog legroups.com:
            >
            >Or run the delegate asycronously using BeginInvoke - in that case, the
            >method will be called on a thread from the thread pool.
            >
            If I do so, I'll have to call EndInvoke correct?
            >
            Yes - you should call endinvoke.

            --
            Tom Shelton

            Comment

            Working...