What I need: I have a WPF/Vb.net application and need to delay a section of code from running, otherwise is keeps running.. I'd like to delay this section of code for 3 seconds.

Problem: I am working with a scale and printer and when a weight item is placed on the scale and a button is pushed to auto-print, the printer will keep spitting out paper. But it should only spit out one sheet. The print should only print one sheet. The app is constantly getting data from the scale, so if something is taken off the scale, it won't print anything. But if the item is left on the scale it will continuously printing. So that's why I was think a delay of some sort would work...Because when auto print is set, they are taking items off, paper should print, then item is taken off, and the next time is put on, paper should print and so on and so on,

I tried: System.Threading.Thread.Sleep(ms) - This does not work because this freezes my entire UI.

Recommended Answers

All 5 Replies

That link isn't very helpful. Its about launching and managing apps from VB.. I don't need to do that.

its for you to read and understand how threading works

The link takes me to a problem that is similar to mine, But the links supplied in that thread really has nothing to do with "threads".

See if this helps.

Public Class Form1
    Private bSendToPrinter As Boolean = False

    Private Sub newScaleItem()
        '// code here to get item when placed on scale.
        '// If Not yourScale.Weight=0.0 Then
        bSendToPrinter = True
        printScaledItem()
        '// End If
    End Sub
    Private Sub printScaledItem()
        If bSendToPrinter Then
            bSendToPrinter = False
            '// Print code here.
        End If
    End Sub
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.