[c#-form] delegates, threads

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • piercy
    New Member
    • Aug 2007
    • 77

    #1

    [c#-form] delegates, threads

    Ok, I’m new to this oo stuff so it sort of confuses the hell out of me at times.. Anyway, I have my main form which contains 3 panels and the center panel gets populated with 6 user controls. So I’m told data flow can only go from the main form to the control and not visa versa. I know there’s a way for it to be done with delegates but the help I have had and the guides I have used, I just don’t understand. it seems like i’m standing in front of my goal but im going to take a 10 mile round trip just because im told to. I don’t understand why I need to do this, or how to do it.

    the problem is made worse because I now need multi threading. I need the main form to kick of a function in usercontrol2 (page2) in a new thread. problem being, I need the app/user control to wait for that thread to finish before continuing. and I need another user control displayed over the top of page 2 until it’s complete.

    now the only way I can see this is working is if I can check the isalive property of the thread. but I don’t know how I would repeat this to allow it to continue when done and I don’t know enough about delegates to do it. all the delegate tutorials show it done on one page of code.. which doesn’t help me at all.

    I know this is quite broad but any hints, tips, reasoning and or coding would be a great help.

    Thanks,
    Piercy
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    Originally posted by piercy
    Ok, I’m new to this oo stuff so it sort of confuses the hell out of me at times.. Anyway, I have my main form which contains 3 panels and the center panel gets populated with 6 user controls. So I’m told data flow can only go from the main form to the control and not visa versa. I know there’s a way for it to be done with delegates but the help I have had and the guides I have used, I just don’t understand. it seems like i’m standing in front of my goal but im going to take a 10 mile round trip just because im told to. I don’t understand why I need to do this, or how to do it.

    the problem is made worse because I now need multi threading. I need the main form to kick of a function in usercontrol2 (page2) in a new thread. problem being, I need the app/user control to wait for that thread to finish before continuing. and I need another user control displayed over the top of page 2 until it’s complete.

    now the only way I can see this is working is if I can check the isalive property of the thread. but I don’t know how I would repeat this to allow it to continue when done and I don’t know enough about delegates to do it. all the delegate tutorials show it done on one page of code.. which doesn’t help me at all.

    I know this is quite broad but any hints, tips, reasoning and or coding would be a great help.

    Thanks,
    Piercy
    Have you tried the backgroundworke r component
    Read up on that...its less messier to use and you can check if the thread has finished or not ans things like that
    it can even report its progress.

    Comment

    • piercy
      New Member
      • Aug 2007
      • 77

      #3
      unfortunatly, im having to devlop in .net 1.1 because the app im developing thid "addon" for has issues with 2.0+.

      although, im now gutted because worker threads looked way easier.

      Thansk again,

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        So what you have is a form. And with that form, you need some action to be performed in another thread. While that is going on you need the UI to show something like "Please wait..." and then remove itself when the action in the other thread is finished.
        Is that right?
        Now where do these user controls fit in?
        What "event"(s) do you need a notice from then?

        Comment

        • piercy
          New Member
          • Aug 2007
          • 77

          #5
          Originally posted by Plater
          So what you have is a form. And with that form, you need some action to be performed in another thread. While that is going on you need the UI to show something like "Please wait..." and then remove itself when the action in the other thread is finished.
          Is that right?
          Now where do these user controls fit in?
          What "event"(s) do you need a notice from then?

          thats exactly it. user controls fit into a panel in the main form. i have several pages and the user controls just show and hide in the panel when need be(ie. next or previous click). i need the function in the thread to finish because page 2 will need the data. i need the please wait part to disappear accordingly. :)

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            The way I've gotten around this is:

            Create a Label (or something) make it pretty big and have it say "Loading... " (or something). Then set it's .Visible property to false.
            When you are going to do your intensive action, set the .Visible property to true. (Make sure you call .Refresh() on the control to make sure it gets shown)
            Then set your program off doing that action. When the action completes, simply set that label with the "Loading... " text back to invisible (.Visible=false )

            Comment

            • piercy
              New Member
              • Aug 2007
              • 77

              #7
              Originally posted by Plater
              The way I've gotten around this is:

              Create a Label (or something) make it pretty big and have it say "Loading... " (or something). Then set it's .Visible property to false.
              When you are going to do your intensive action, set the .Visible property to true. (Make sure you call .Refresh() on the control to make sure it gets shown)
              Then set your program off doing that action. When the action completes, simply set that label with the "Loading... " text back to invisible (.Visible=false )

              yes, i thought of this but apprently its not proper coding. The idea being(i think) as im a trainee programmer, they want me to leanr it properly from the start so im having to learn oo c#. anyway, got a small problem now im trying it a different way. used a showdialog() to open the box and the thread does in the background then at the end of the thread i put a box.Dispose() to close it and i get the error Cannot access a disposed object. im having alook arodun for answers but if you got nay let me know.

              Thanks,
              piercy

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Use .Close() and not .Dispose() to close the window.
                Then you can get your information from it.
                THEN you can call .Dispose()


                I'm not sure what wasn't proper coding about all that. It's better then what I see most programs do (which is give you NO feedback)

                Comment

                • piercy
                  New Member
                  • Aug 2007
                  • 77

                  #9
                  Originally posted by Plater
                  Use .Close() and not .Dispose() to close the window.
                  Then you can get your information from it.
                  THEN you can call .Dispose()


                  I'm not sure what wasn't proper coding about all that. It's better then what I see most programs do (which is give you NO feedback)
                  yeah, i tried the close thing but it didnt work. so i've just hid it. does the job. as for proper code.. been huge pain in my... had to rewrite my whole app because of it. almost there though. few delaget things to do with the box now for cancel clicks etc.. *cries* i hate delegates.. dont understadn them at all. i gto sample code to do them but dont understand it. makes it really hard to learn..

                  Thanks again,
                  piercy

                  Comment

                  Working...