Results 1 to 6 of 6

Thread: Threading

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    180

    Threading

    I want to build a simple utility to stress test a database application, in short I want to create 500 threads which all run the same query against an SQL database. How do I create the threads?

    Thanks

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Threading

    You're nuts

  3. #3
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Threading

    VB Code:
    1. Private Sub Button_Click(...)
    2. For i As Integer = 1 to 500
    3.     Dim StressThread As New Threading.Thread(AddressOf QueryDataBase)
    4.     StressThread.Start()
    5. Next i
    6. End Sub
    7.    
    8.  
    9. Private Sub QueryDataBase()
    10. '..Stuff here
    11. End Sub
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: Threading

    Here is an article about threading probably a good place to start
    http://www.startvbdotnet.com/threading/default.aspx
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    180

    Re: Threading

    Okay that works great thanks. However, if I run the program a second time it complains about low virtual memory then crashes, presumably becuase theres too many threads still present from the previous time.

    Is there any way I can iterate through all the current threads and dispose of them prior to starting again?

    I have this

    For Each t As Threading.Thread In System.Diagnostics.Process.GetCurrentProcess.Threads
    t.Abort()
    Next

    But it fails with an invalidcastexception

    Also I dont obviously want to abort the thread which the ui is running on?

    Thanks

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Threading

    Set the threads IsBackground property to True if you want them to be aborted and disposed immediately when the program is closed.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

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