Results 1 to 10 of 10

Thread: Pause code until event fires

  1. #1

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Pause code until event fires

    I'm building a class that controls the showing of multiple forms that step through a generic sales transaction....

    The general scheme is this:

    I make a call to the class.... myTransaction.Start()

    That class first displays a form to the user to select his sales rep id... once the user clicks the button to identify himself... this form returns back to the class with an instance of salesman.

    Then the class displays a form to the user to select a customer.... once that information is entered, it returns back to the class with an instance of a customer...

    and so on....

    Right now, I am having to implement a Do-While Salesman = Nothing... which loops until the user clicks a button which sets the Salesman to a particular instance. Then the form method returns to the class the salesman...

    Is there a better way to handle this? I was thinking perhaps using an event based callback... but I'm not sure how that would work...

    Transaction class:
    VB Code:
    1. Public Sub Start()
    2.       SelectASalesMan.Show  'actually a little more complicated
    3.                                             'since I would use a navigation function to determine where to go
    4.                                             'but this suffices for simplicity sake
    5.                                             'at this point though, the transaction class would resume control back to whomever called it          
    6. End Sub
    7.  
    8. Private Sub SalesManSelected(sender as object, e as system.eventargs) Handles MessageSent
    9.      
    10. End Sub

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    You could put all the code you need to pause into a thread. Then you have full control of stopping ,pausing, sleeping, and/or starting the thread when you need to.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Yea... I was thinking along the lines of threads, but didn't want to have to crack the can until absolutely necessary...

    I would need a call that would sleep the thread until an event in another thread fired, singaling the paused thread it was safe to resume... however, how would i pass an object back to a paused thread?

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    I was wondering the same thing. I think a callback is the term, but I really havent gotten into that one yet . I got a whole book on this stuff, but havent had a chance to read it yet.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If you are always using a form to gather the info then just show it modally, use ShowDialog instead of Show. You can shadow the Dialogresult that the Showdialog function returns too if you want, then you can basically call the form like a function.

  6. #6

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    ah... brilliant... that would work in my scenario... i hope someone's paying you BIG bucks...

  7. #7

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Well, if you have a few minutes... how would i successfully implement that....



    VB Code:
    1. Private Shadows dialogresult As SalesRep
    2. '
    3. '
    4. '
    5. Protected Overloads Function ShowDialog() As SalesRep
    6.  
    7. End Function
    8.  
    9. '?

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    My website loads slow but here is a bit on this:

    http://www.edneeis.com/Code/CustomFormResult.asp

    There is a link to a sample app in the top description part.

  9. #9

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Ah handy website there....

    Ok... thanks again...

  10. #10
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    It could use some work and I have a ton of stuff I need to add, but I've been lazy, but thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width