Would I be better off using a new thread for this?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nodoid
    New Member
    • May 2010
    • 19

    Would I be better off using a new thread for this?

    Hi,

    I have a sound file playing which lasts 50 seconds say. At 30 seconds, I need a new window to open and load a picture.

    Would I be better off creating a new timer, when it hits 30 seconds, fire the new window or would I be better off creating a new thread, have the timer in the thread, fire at 30 seconds then kill the thread?

    Or is there something I can just use in .NET which does this sort of thing (a special timer or something that latches onto the sound player.

    I'm using the following to play the sound currently

    Code:
    [System.Runtime.InteropServices.DllImport("coredll.dll")]
    
    private static extern int PlaySound(byte[] szSound, int Mod, int flags);
    
    System.IO.Stream wav = _assembly.GetManifestResourceStream("h:\new.wav");
    
    Byte[] soundBytes = new Byte[wav.Length];
    
    wav.Read(soundBytes, 0, (int)wav.Length);
    
    int res=PlaySound(soundBytes, 0, 0x0005); //SND_MEMORY | SND_ASYNC
    Thanks

    Paul
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    Originally posted by nodoid
    Hi,

    I have a sound file playing which lasts 50 seconds say. At 30 seconds, I need a new window to open and load a picture.

    Would I be better off creating a new timer, when it hits 30 seconds, fire the new window or would I be better off creating a new thread, have the timer in the thread, fire at 30 seconds then kill the thread?

    Or is there something I can just use in .NET which does this sort of thing (a special timer or something that latches onto the sound player.

    I'm using the following to play the sound currently

    Code:
    [System.Runtime.InteropServices.DllImport("coredll.dll")]
    
    private static extern int PlaySound(byte[] szSound, int Mod, int flags);
    
    System.IO.Stream wav = _assembly.GetManifestResourceStream("h:\new.wav");
    
    Byte[] soundBytes = new Byte[wav.Length];
    
    wav.Read(soundBytes, 0, (int)wav.Length);
    
    int res=PlaySound(soundBytes, 0, 0x0005); //SND_MEMORY | SND_ASYNC
    Thanks

    Paul
    You should use a Timer instead of threads...
    Start the timer as soon as you trigger the Play() function..

    and give it an interval of 50 sec i.e. 50000 milliseconds as the timer interval.

    Comment

    Working...