Results 1 to 8 of 8

Thread: [RESOLVED] Why is my clock not ticking ?

  1. #1

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,429

    Resolved [RESOLVED] Why is my clock not ticking ?

    This subroutine has been giving me trouble for two days now.
    Code:
    Imports CoreAudio
    
        Private Sub TimerTick() Handles Timer1.Tick
            My.Computer.Audio.Play(My.Resources.Tikk, AudioPlayMode.Background)     
        End Sub
    Timer1 is running, Timer1 Interval is set to 100 and Tikk.wav is only 60 milliseconds long but it only plays once in a blue moon.
    CoreAudio.DLL has been added to References, and is in the bin folder, the computer volume is at 100%
    I've stripped this subroutine down to the bare minimum as shown, but I still don't get a tick sound every second.

    I can see no reason why not.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Why is my clock not ticking ?

    Don't know much about this type of process but do you realize that 100ms is only 1 tenth of a second. Can you really load a resource and play a wav file in 1 tenth of a second. Also maybe increase the duration of the tikk. I could be way off but that's the first thing that struck me.

  3. #3

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,429

    Re: Why is my clock not ticking ?

    Oh Bugger !

    I had it set to 100 earlier when I was running at a tenth, then I realised that I didn't need to be that precise, changed it to seconds, changed the interval to 1000, then when something went wrong, I did 'undo' a few times to get back to where I'd gone wrong, forgot to change that back to 1000 because I was so used to it being 100.

    Easy to overlook the obvious. It's ticking away merrily again now.

    Thanks Wes.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: [RESOLVED] Why is my clock not ticking ?

    I think that I have mentioned this before but every time you access a property of My.Resources you create a new object, which means that the data has to be extracted from the EXE again. Don't do that. Extract your resource once only, assign it to a field and then use that field each time. If you know for a fact that you will use the data then just initialise the field where you declare it, e.g.
    vb.net Code:
    1. Private ReadOnly tikk As Byte() = My.Resources.Tikk
    If you may not use it at all then use a property that will extract the resource on the first use, e.g.
    vb.net Code:
    1. Private _tikk As Byte()
    2.  
    3. Private ReadOnly Tikk As Byte()
    4.     Get
    5.         If _tikk Is Nothing Then
    6.             _tikk = My.Resources.Tikk
    7.         End If
    8.  
    9.         Return _tikk
    10.     End Get
    11. End Property

  5. #5

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,429

    Re: [RESOLVED] Why is my clock not ticking ?

    Thanks John,

    I'll bear that in mind, I don't remember you telling me that before, but then, my memory's not what it used to be.
    I had to give up the bridge club a few years ago my memory was embarrassing me, and worse I'm sure it was upsetting my bridge partner.

    I've already implemented your suggestion in this and four previous projects. I'll wade through a load more once I've put this particular one to bed.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: [RESOLVED] Why is my clock not ticking ?

    Quote Originally Posted by Poppa Mintin View Post
    I'll bear that in mind, I don't remember you telling me that before, but then, my memory's not what it used to be.
    I've mentioned it once or twice recently but don't recall to whom. My memory is what it used to be, which is no great recommendation.
    Quote Originally Posted by Poppa Mintin View Post
    I had to give up the bridge club a few years ago my memory was embarrassing me, and worse I'm sure it was upsetting my bridge partner.
    Plot twist: it was canasta but you forgot.

  7. #7

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,429

    Re: [RESOLVED] Why is my clock not ticking ?

    I only did four previous projects because on the fifth I got an error:
    Error BC30311 Value of type 'UnmanagedMemoryStream' cannot be converted to 'Byte()'.
    When I couldn't find what that meant, I went back to the project in progress.

    Maybe it's missing an Import ?


    Poppa
    Last edited by Poppa Mintin; Aug 13th, 2020 at 05:20 AM.
    Along with the sunshine there has to be a little rain sometime.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: [RESOLVED] Why is my clock not ticking ?

    The type of a My.Resources property depends on the type of the file added in the first place. I'm not sure but it may depend on other factors too, e.g. the size file. It may be that a Byte array is returned up to a particular size and an UnmanagedMemoryStream is returned for larger data or it may just depend on file type. Regardless, and UnmanagedMemoryStream can be treated pretty much like any other Stream. That Play method you're calling does have an overload that will accept a Stream so, in theory, you could do exactly the same thing but declare the field/property as type Stream or UnmanagedMemoryStream instead of Byte().

    That said, I don't think that that's a good idea. That would mean keeping the Stream open all the time and you'd just end up reading the data over and over anyway. If you were going to do that, you may as well just pass the My.Resources property as you were in the first place. Instead, assuming that the amount of data is not to large, you should get the Stream once, read the data from it into a Byte array and then close the Stream. Now you have a Byte array that you can use in the same way as you already are.

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