Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. mciSendString working only on main Thread?

mciSendString working only on main Thread?

Scheduled Pinned Locked Moved C#
designhelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mikker_123
    wrote on last edited by
    #1

    Hi, I was just wondering if anybody else has same problem -> I can't seem to get this to work on other than UI thread. So this works if you call it directly on form

        \[DllImport("winmm.dll")\]
        private static extern long mciSendString(string strCommand,
            string strReturn, int iReturnLength, IntPtr hwndCallback);
    

    private void OnSomeButtonClick()
    {
    PlaySound(new object[] {"c:/sound.mp3", this.Handle});
    }

        private void PlaySound(object soundToPlay)
        {
            string soundToPlay = ((object\[\])data)\[0\];
            Handle handle = ((object\[\])data)\[1\];
    
            string sCommand = "open \\"" + soundToPlay + "\\" type mpegvideo alias MediaFile";
            mciSendString(sCommand, null, 0, IntPtr.Zero);
    
            sCommand = "play MediaFile wait";
            mciSendString(sCommand, null, 0, handle);
    
            string sCommand = "close MediaFile";
            mciSendString(sCommand, null, 0, IntPtr.Zero);
        }
    

    But if you say:

    private void OnSomeButtonClick()
    {
    ThreadPool.QueueUserWorkItem(new WaitCallback(PlaySound), new object[] {"c:/sound.mp3", this.Handle});
    }

    It won't play sound... anyone? Tnx in advance

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups