jan1024188_1

Hello,

I have two questions:

1. How to make a thread in C# that will play a sound like DWORD WINAPI threadplaysnd(LPVOID) { PlaySound("audio.wav",NULL,SND_FILENAME | SND_ASYNC | SND_LOOP); return 0;}
CreateThread(0,0,threadplaysnd,0,0,&dwthreadplaysnd);

In Winapi.


2. How to make an application execute like ShellExecute( NULL, "open", "file.exe", NULL, "", SW_SHOW ); in Winapi.

Thanks in advance




Re: Visual C# General Make a thread

jan1024188_1

Ok, Ive managed with sound:

System.Media.SoundPlayer sp = new System.Media.SoundPlayer();
public Form1()
{
InitializeComponent();

sp.SoundLocation = AppDomain.CurrentDomain.BaseDirectory + "\\audio.wav";
sp.Load();
sp.Play();


}


and

private void button1_Click_1(object sender, EventArgs e)
{
sp.Stop();
}


What about executing a file






Re: Visual C# General Make a thread

Bruno_1

About running an application,
Process.Start("file.exe");
To create a thread and run it, you should first specify a method, that will be wraped to a delegate, then passed as a parameter to a thread constructor;
In code:
Code Snippet


public void Main()

{

Thread th = new Thread(playsound);

th.Start();

}


public void playsound()
{
// Here you play the sound
}







Re: Visual C# General Make a thread

jan1024188_1

Thanks but I get a compiler error:
Code Snippet



Error 1 The name 'Process' does not exist in the current context C:\Users\jan\Documents\Visual Studio 2005\Projects\Untitled - The game menu\Untitled - The game menu\Form1.cs 36 13 Untitled - The game menu






Re: Visual C# General Make a thread

Bruno_1

you should include the namespace where Process is located, this should notified in intellisense, however you can do it manually by:
using System.Diagnostics;

Also you can use : System.Diagnostics.Process.Start(...);

Hope this helped





Re: Visual C# General Make a thread

jan1024188_1

work as charm Smile