Click here to Skip to main content
15,904,817 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Import CSV file to MS Access Pin
scothykonma20-Aug-08 22:57
scothykonma20-Aug-08 22:57 
AnswerRe: Import CSV file to MS Access Pin
Mycroft Holmes20-Aug-08 19:13
professionalMycroft Holmes20-Aug-08 19:13 
QuestionUnedited Articles Pin
Taylor Kobani20-Aug-08 8:35
Taylor Kobani20-Aug-08 8:35 
AnswerRe: Unedited Articles Pin
jzonthemtn20-Aug-08 9:29
jzonthemtn20-Aug-08 9:29 
AnswerRe: Unedited Articles Pin
Christian Graus20-Aug-08 15:12
protectorChristian Graus20-Aug-08 15:12 
QuestionA couple Datagridview column header formatting questions [modified] Pin
Jon_Boy20-Aug-08 8:20
Jon_Boy20-Aug-08 8:20 
QuestionWait in Background Worker Pin
captainmogo20-Aug-08 7:23
captainmogo20-Aug-08 7:23 
AnswerRe: Wait in Background Worker Pin
Gideon Engelberth20-Aug-08 7:44
Gideon Engelberth20-Aug-08 7:44 
Yes (and yes). There are two ways that come to mind if you need this kind of a wait. If you will not ever need to cancel the wait, you can just use Thread.Sleep, but if you may need to cancel (eg: to shut the thread down immediately), you can use an AutoResetEvent (or one of the other similar System.Threading classes).

As far as the variable wait time, just encapsulate the DoWork event handler in a class with the wait time as a field or property.

Here's a simple console app sample to demonstrate the two ways. Uncomment the lines and comment the Thread.Sleep line to use the AutoResetEvent instead.

Dim waitTime As Integer
Dim handle As New System.Threading.AutoResetEvent(False)

Sub Main()
    Dim rand As New System.Random
    waitTime = rand.Next(10, 20)
    Dim bw As New System.ComponentModel.BackgroundWorker
    AddHandler bw.DoWork, AddressOf WorkerRoutine

    Console.WriteLine("Wait time will be {0} seconds", waitTime)
    bw.RunWorkerAsync()
    'Console.WriteLine("Press any key to interrupt the worker.")
    'Console.ReadKey()
    'handle.Set()
     
    Console.WriteLine("Program complete...")
    Console.ReadKey()
End Sub

Private Sub WorkerRoutine(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
    Console.WriteLine("Beginning work")
    System.Threading.Thread.Sleep(waitTime * 1000)  'gives a non-interruptable sleep
    'handle.WaitOne(waitTime * 1000, False)   'gives an interruptable "sleep" period
    Console.WriteLine("Ending work")
End Sub

QuestionConnect to a password protected Access database!! Pin
John Kh20-Aug-08 7:09
John Kh20-Aug-08 7:09 
AnswerRe: Connect to a password protected Access database!! Pin
Kschuler20-Aug-08 10:25
Kschuler20-Aug-08 10:25 
AnswerRe: Connect to a password protected Access database!! Pin
emimmortal20-Aug-08 19:01
emimmortal20-Aug-08 19:01 
GeneralRe: Connect to a password protected Access database!! Pin
John Kh22-Aug-08 22:56
John Kh22-Aug-08 22:56 
QuestionVB:net mysql subtract value Pin
Pestinha198420-Aug-08 6:06
Pestinha198420-Aug-08 6:06 
AnswerRe: VB:net mysql subtract value Pin
Gideon Engelberth20-Aug-08 7:45
Gideon Engelberth20-Aug-08 7:45 
GeneralRe: VB:net mysql subtract value Pin
Pestinha198420-Aug-08 7:53
Pestinha198420-Aug-08 7:53 
QuestionHow can i count bytes in an array of bytes ? Pin
Kobi_Z20-Aug-08 5:00
Kobi_Z20-Aug-08 5:00 
GeneralRe: How can i count bytes in an array of bytes ? Pin
Kschuler20-Aug-08 10:27
Kschuler20-Aug-08 10:27 
GeneralRe: How can i count bytes in an array of bytes ? Pin
Kobi_Z21-Aug-08 9:24
Kobi_Z21-Aug-08 9:24 
QuestionFunction declaration that returns array Pin
indian14320-Aug-08 3:58
indian14320-Aug-08 3:58 
AnswerRe: Function declaration that returns array Pin
cstrader23220-Aug-08 4:31
cstrader23220-Aug-08 4:31 
AnswerRe: Function declaration that returns array Pin
MikeMarq20-Aug-08 6:47
MikeMarq20-Aug-08 6:47 
GeneralThe 1 votes Pin
MikeMarq20-Aug-08 15:46
MikeMarq20-Aug-08 15:46 
GeneralRe: The 1 votes Pin
cstrader23220-Aug-08 16:17
cstrader23220-Aug-08 16:17 
GeneralRe: The 1 votes Pin
MikeMarq20-Aug-08 16:25
MikeMarq20-Aug-08 16:25 
GeneralRe: The 1 votes Pin
Mycroft Holmes20-Aug-08 19:16
professionalMycroft Holmes20-Aug-08 19:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.