Help with threads/delegates

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

    Help with threads/delegates

    Hi There

    I have a method called MyMethod in Class MyClass. Whenever MyMethod is
    called I want to fire off a new thread to call another method called
    MyEventMethod. I want to fire this method off on a new thread as I don't
    want to wait for it to finish processing before returning to my calling app.
    How should I do this? Here is some sample code:


    public class MyClass
    {
    public MyClass()
    {
    }

    public void MyMethod(int Param1, int Param2)
    {
    // Do something
    }

    public void MyEventMethod(i nt Param1, int Param2)
    {
    // Do something
    }
    }

    Thanks,

    S


  • Joey Powell

    #2
    Re: Help with threads/delegates

    I would also be very interested in seeing some sample code on how to
    do this - nothing fancy. Just enough to get the job done.

    "SamIAm" <samiam@rubbach icken.com> wrote in message news:<eF9sdg3aD HA.2580@TK2MSFT NGP09.phx.gbl>. ..[color=blue]
    > Hi There
    >
    > I have a method called MyMethod in Class MyClass. Whenever MyMethod is
    > called I want to fire off a new thread to call another method called
    > MyEventMethod. I want to fire this method off on a new thread as I don't
    > want to wait for it to finish processing before returning to my calling app.
    > How should I do this? Here is some sample code:
    >
    >
    > public class MyClass
    > {
    > public MyClass()
    > {
    > }
    >
    > public void MyMethod(int Param1, int Param2)
    > {
    > // Do something
    > }
    >
    > public void MyEventMethod(i nt Param1, int Param2)
    > {
    > // Do something
    > }
    > }
    >
    > Thanks,
    >
    > S[/color]

    Comment

    • Kieran Benton

      #3
      Re: Help with threads/delegates

      Me three :)

      Is there any way of implementing something like an .Invoke in a thread ive
      created? So that one thread can get another thread to call a method in its
      time?

      Thanks
      Kieran

      "Joey Powell" <joey.powell@go ldcoinc.com> wrote in message
      news:bdaf8387.0 308252158.4b1e2 e5a@posting.goo gle.com...[color=blue]
      > I would also be very interested in seeing some sample code on how to
      > do this - nothing fancy. Just enough to get the job done.
      >
      > "SamIAm" <samiam@rubbach icken.com> wrote in message[/color]
      news:<eF9sdg3aD HA.2580@TK2MSFT NGP09.phx.gbl>. ..[color=blue][color=green]
      > > Hi There
      > >
      > > I have a method called MyMethod in Class MyClass. Whenever MyMethod is
      > > called I want to fire off a new thread to call another method called
      > > MyEventMethod. I want to fire this method off on a new thread as I don't
      > > want to wait for it to finish processing before returning to my calling[/color][/color]
      app.[color=blue][color=green]
      > > How should I do this? Here is some sample code:
      > >
      > >
      > > public class MyClass
      > > {
      > > public MyClass()
      > > {
      > > }
      > >
      > > public void MyMethod(int Param1, int Param2)
      > > {
      > > // Do something
      > > }
      > >
      > > public void MyEventMethod(i nt Param1, int Param2)
      > > {
      > > // Do something
      > > }
      > > }
      > >
      > > Thanks,
      > >
      > > S[/color][/color]


      Comment

      • Kieran Benton

        #4
        Re: Help with threads/delegates

        Dave,
        Any useful resources/links?

        Thanks again

        "Dave" <kdlevine@wi.rr .com> wrote in message
        news:Ob7LTn7aDH A.2072@TK2MSFTN GP10.phx.gbl...[color=blue]
        > If it's a UI thread with controls then you can use Control.Invoke. If it's[/color]
        a[color=blue]
        > worker thread with no UI then you will need to implement your own[/color]
        signalling[color=blue]
        > mechanism.
        >
        > "Kieran Benton" <kieranbenton@h otmail.com> wrote in message
        > news:%23MN6Hz6a DHA.388@TK2MSFT NGP10.phx.gbl.. .[color=green]
        > > Me three :)
        > >
        > > Is there any way of implementing something like an .Invoke in a thread[/color][/color]
        ive[color=blue][color=green]
        > > created? So that one thread can get another thread to call a method in[/color][/color]
        its[color=blue][color=green]
        > > time?
        > >
        > > Thanks
        > > Kieran
        > >
        > > "Joey Powell" <joey.powell@go ldcoinc.com> wrote in message
        > > news:bdaf8387.0 308252158.4b1e2 e5a@posting.goo gle.com...[color=darkred]
        > > > I would also be very interested in seeing some sample code on how to
        > > > do this - nothing fancy. Just enough to get the job done.
        > > >
        > > > "SamIAm" <samiam@rubbach icken.com> wrote in message[/color]
        > > news:<eF9sdg3aD HA.2580@TK2MSFT NGP09.phx.gbl>. ..[color=darkred]
        > > > > Hi There
        > > > >
        > > > > I have a method called MyMethod in Class MyClass. Whenever MyMethod[/color][/color][/color]
        is[color=blue][color=green][color=darkred]
        > > > > called I want to fire off a new thread to call another method called
        > > > > MyEventMethod. I want to fire this method off on a new thread as I[/color][/color]
        > don't[color=green][color=darkred]
        > > > > want to wait for it to finish processing before returning to my[/color][/color]
        > calling[color=green]
        > > app.[color=darkred]
        > > > > How should I do this? Here is some sample code:
        > > > >
        > > > >
        > > > > public class MyClass
        > > > > {
        > > > > public MyClass()
        > > > > {
        > > > > }
        > > > >
        > > > > public void MyMethod(int Param1, int Param2)
        > > > > {
        > > > > // Do something
        > > > > }
        > > > >
        > > > > public void MyEventMethod(i nt Param1, int Param2)
        > > > > {
        > > > > // Do something
        > > > > }
        > > > > }
        > > > >
        > > > > Thanks,
        > > > >
        > > > > S[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Dave

          #5
          Re: Help with threads/delegates

          Not any that I could easily find via google. I think I might write a little
          class that provides that functionality.. .it seems to be a common enough
          request.

          "Kieran Benton" <kieranbenton@h otmail.com> wrote in message
          news:uP9Mdx7aDH A.3360@tk2msftn gp13.phx.gbl...[color=blue]
          > Dave,
          > Any useful resources/links?
          >
          > Thanks again
          >
          > "Dave" <kdlevine@wi.rr .com> wrote in message
          > news:Ob7LTn7aDH A.2072@TK2MSFTN GP10.phx.gbl...[color=green]
          > > If it's a UI thread with controls then you can use Control.Invoke. If[/color][/color]
          it's[color=blue]
          > a[color=green]
          > > worker thread with no UI then you will need to implement your own[/color]
          > signalling[color=green]
          > > mechanism.
          > >
          > > "Kieran Benton" <kieranbenton@h otmail.com> wrote in message
          > > news:%23MN6Hz6a DHA.388@TK2MSFT NGP10.phx.gbl.. .[color=darkred]
          > > > Me three :)
          > > >
          > > > Is there any way of implementing something like an .Invoke in a thread[/color][/color]
          > ive[color=green][color=darkred]
          > > > created? So that one thread can get another thread to call a method in[/color][/color]
          > its[color=green][color=darkred]
          > > > time?
          > > >
          > > > Thanks
          > > > Kieran
          > > >
          > > > "Joey Powell" <joey.powell@go ldcoinc.com> wrote in message
          > > > news:bdaf8387.0 308252158.4b1e2 e5a@posting.goo gle.com...
          > > > > I would also be very interested in seeing some sample code on how to
          > > > > do this - nothing fancy. Just enough to get the job done.
          > > > >
          > > > > "SamIAm" <samiam@rubbach icken.com> wrote in message
          > > > news:<eF9sdg3aD HA.2580@TK2MSFT NGP09.phx.gbl>. ..
          > > > > > Hi There
          > > > > >
          > > > > > I have a method called MyMethod in Class MyClass. Whenever[/color][/color][/color]
          MyMethod[color=blue]
          > is[color=green][color=darkred]
          > > > > > called I want to fire off a new thread to call another method[/color][/color][/color]
          called[color=blue][color=green][color=darkred]
          > > > > > MyEventMethod. I want to fire this method off on a new thread as I[/color]
          > > don't[color=darkred]
          > > > > > want to wait for it to finish processing before returning to my[/color]
          > > calling[color=darkred]
          > > > app.
          > > > > > How should I do this? Here is some sample code:
          > > > > >
          > > > > >
          > > > > > public class MyClass
          > > > > > {
          > > > > > public MyClass()
          > > > > > {
          > > > > > }
          > > > > >
          > > > > > public void MyMethod(int Param1, int Param2)
          > > > > > {
          > > > > > // Do something
          > > > > > }
          > > > > >
          > > > > > public void MyEventMethod(i nt Param1, int Param2)
          > > > > > {
          > > > > > // Do something
          > > > > > }
          > > > > > }
          > > > > >
          > > > > > Thanks,
          > > > > >
          > > > > > S
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Kieran Benton

            #6
            Re: Help with threads/delegates

            That would be pretty cool. Im pretty savvy in all things C# but im jsut
            learning the intracacies of threading and getting very muddled up :) could i
            see what your working on and maybe contribute?

            Thanks
            Kieran

            "Dave" <dlevineNNTP@wi .rr.com> wrote in message
            news:%23fPDZ$7a DHA.3248@tk2msf tngp13.phx.gbl. ..[color=blue]
            > Not any that I could easily find via google. I think I might write a[/color]
            little[color=blue]
            > class that provides that functionality.. .it seems to be a common enough
            > request.
            >
            > "Kieran Benton" <kieranbenton@h otmail.com> wrote in message
            > news:uP9Mdx7aDH A.3360@tk2msftn gp13.phx.gbl...[color=green]
            > > Dave,
            > > Any useful resources/links?
            > >
            > > Thanks again
            > >
            > > "Dave" <kdlevine@wi.rr .com> wrote in message
            > > news:Ob7LTn7aDH A.2072@TK2MSFTN GP10.phx.gbl...[color=darkred]
            > > > If it's a UI thread with controls then you can use Control.Invoke. If[/color][/color]
            > it's[color=green]
            > > a[color=darkred]
            > > > worker thread with no UI then you will need to implement your own[/color]
            > > signalling[color=darkred]
            > > > mechanism.
            > > >
            > > > "Kieran Benton" <kieranbenton@h otmail.com> wrote in message
            > > > news:%23MN6Hz6a DHA.388@TK2MSFT NGP10.phx.gbl.. .
            > > > > Me three :)
            > > > >
            > > > > Is there any way of implementing something like an .Invoke in a[/color][/color][/color]
            thread[color=blue][color=green]
            > > ive[color=darkred]
            > > > > created? So that one thread can get another thread to call a method[/color][/color][/color]
            in[color=blue][color=green]
            > > its[color=darkred]
            > > > > time?
            > > > >
            > > > > Thanks
            > > > > Kieran
            > > > >
            > > > > "Joey Powell" <joey.powell@go ldcoinc.com> wrote in message
            > > > > news:bdaf8387.0 308252158.4b1e2 e5a@posting.goo gle.com...
            > > > > > I would also be very interested in seeing some sample code on how[/color][/color][/color]
            to[color=blue][color=green][color=darkred]
            > > > > > do this - nothing fancy. Just enough to get the job done.
            > > > > >
            > > > > > "SamIAm" <samiam@rubbach icken.com> wrote in message
            > > > > news:<eF9sdg3aD HA.2580@TK2MSFT NGP09.phx.gbl>. ..
            > > > > > > Hi There
            > > > > > >
            > > > > > > I have a method called MyMethod in Class MyClass. Whenever[/color][/color]
            > MyMethod[color=green]
            > > is[color=darkred]
            > > > > > > called I want to fire off a new thread to call another method[/color][/color]
            > called[color=green][color=darkred]
            > > > > > > MyEventMethod. I want to fire this method off on a new thread as[/color][/color][/color]
            I[color=blue][color=green][color=darkred]
            > > > don't
            > > > > > > want to wait for it to finish processing before returning to my
            > > > calling
            > > > > app.
            > > > > > > How should I do this? Here is some sample code:
            > > > > > >
            > > > > > >
            > > > > > > public class MyClass
            > > > > > > {
            > > > > > > public MyClass()
            > > > > > > {
            > > > > > > }
            > > > > > >
            > > > > > > public void MyMethod(int Param1, int Param2)
            > > > > > > {
            > > > > > > // Do something
            > > > > > > }
            > > > > > >
            > > > > > > public void MyEventMethod(i nt Param1, int Param2)
            > > > > > > {
            > > > > > > // Do something
            > > > > > > }
            > > > > > > }
            > > > > > >
            > > > > > > Thanks,
            > > > > > >
            > > > > > > S
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            Working...