none
how to count 3 seconds before running the code? RRS feed

  • Question

  • Hi,

    I have a POS software with a txtBarCode textbox. I want when the user scan the bar code and after the textbox was idle for 3 seconds to run find_product() class?

    How can I do this please?

    also if you have a better idea to perform the same?

    Thanks
    Monday, February 17, 2014 2:30 PM

Answers

  • as you say the barcode length is not the same for al products, so there is no guarantee that even 3 secs are going to be enough.

    So that makes it even more important not to wait and just respond to a call back. I'm sure the driver for the barcode reader would be providing a callback to the software, and this callback would be invoked by the driver only after the scan has been completed.

    Either the above or, there must be a status available, that should be polled by our software to check if the scan is completed and then respond.

    Wednesday, February 19, 2014 9:01 AM

All replies

  • One option is to handle the Blur(Text Changed) event. On this event you can use the thread.sleep(3seconds) and then continue processing.

    But this will hang the UI for 3 seconds.

    Alternative is to use BackgroundWorker threads which can be invoked from the textchanged events.


    Microsoft Virtual Academy!
    A.m.a.L Hashim
    Microsoft Most Valuable Professional
    My Blog - Dot Net Goodies

    Monday, February 17, 2014 2:37 PM
  • From what i have understood, I don't see the need for a sleep here. You just want to respond to a scan and run your find_product() method.

    So you should just run this method in the callback that gets invoked after the scan. There is no need to wait for 3 seconds.

    Tuesday, February 18, 2014 11:22 AM
  • but how will I know the scan was completed if I don't sleep for seconds? keeping in mind barcode length is not the same for all products..

    Please advise

    Tuesday, February 18, 2014 11:24 AM
  • as you say the barcode length is not the same for al products, so there is no guarantee that even 3 secs are going to be enough.

    So that makes it even more important not to wait and just respond to a call back. I'm sure the driver for the barcode reader would be providing a callback to the software, and this callback would be invoked by the driver only after the scan has been completed.

    Either the above or, there must be a status available, that should be polled by our software to check if the scan is completed and then respond.

    Wednesday, February 19, 2014 9:01 AM