Notify from worker thread

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

    #1

    Notify from worker thread

    Hi

    I still have problem with this. I wan't to execute a method in main thread
    after worker thread completes some work. In GUI application I'd use
    Control.Invoke (control would be the main form), but the same thread could
    be run from console app or WebService app. What would be the mechanism of
    executing method in main thread with these two apps? If the same, I'd have
    to create some kind of windowed control. It's probably legal to do this in
    WebService right :)?

    regards
    Tomaz


  • AlexS

    #2
    Re: Notify from worker thread

    Tomasz,

    probably easiest way is to define event in the thread and assign event
    handler to it in your main thread when starting. Or to pass delegate like
    callback.

    HTH
    Alex

    "Tomaz Koritnik" <nospam@nospam. com> wrote in message
    news:Z5Wpe.1259 4$F6.2676570@ne ws.siol.net...[color=blue]
    > Hi
    >
    > I still have problem with this. I wan't to execute a method in main thread
    > after worker thread completes some work. In GUI application I'd use
    > Control.Invoke (control would be the main form), but the same thread could
    > be run from console app or WebService app. What would be the mechanism of
    > executing method in main thread with these two apps? If the same, I'd have
    > to create some kind of windowed control. It's probably legal to do this in
    > WebService right :)?
    >
    > regards
    > Tomaz
    >
    >[/color]


    Comment

    • Richard Blewett [DevelopMentor]

      #3
      Re: Notify from worker thread

      In this situation its useful to realise that, Control.Invoke or BeginInvoke are simply the Control's implementation of ISynchronizeInv oke.Invoke and BeginInvoke. So for console and web apps, simply create an implementation of ISynchronizeInv oke that updates the necessary data (using locking where necessary) and pass that to the component.

      Regards

      Richard Blewett - DevelopMentor



      Hi

      I still have problem with this. I wan't to execute a method in main thread
      after worker thread completes some work. In GUI application I'd use
      Control.Invoke (control would be the main form), but the same thread could
      be run from console app or WebService app. What would be the mechanism of
      executing method in main thread with these two apps? If the same, I'd have
      to create some kind of windowed control. It's probably legal to do this in
      WebService right :)?

      regards
      Tomaz

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Notify from worker thread

        Tomaz Koritnik <nospam@nospam. com> wrote:[color=blue]
        > I still have problem with this. I wan't to execute a method in main thread
        > after worker thread completes some work. In GUI application I'd use
        > Control.Invoke (control would be the main form), but the same thread could
        > be run from console app or WebService app. What would be the mechanism of
        > executing method in main thread with these two apps? If the same, I'd have
        > to create some kind of windowed control. It's probably legal to do this in
        > WebService right :)?[/color]

        Well, what is the main thread doing while all this is happening? You
        basically need it to be waiting for an event of some description.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        Working...