Problème avec thread jouant un son!

Résolu
cs_othland Messages postés 298 Date d'inscription jeudi 18 décembre 2003 Statut Membre Dernière intervention 9 février 2010 - 7 avril 2006 à 10:08
cs_othland Messages postés 298 Date d'inscription jeudi 18 décembre 2003 Statut Membre Dernière intervention 9 février 2010 - 7 avril 2006 à 11:26
slt tlm;
je voulais concevoir un programme qui lance un thread qui lui même surveille l'horloge système pour lancer un son, le problème c'est que quand l'heure arrive, je n'entend pas le son...??? je comprend pas pkoi??
mon code:
<code>
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
public static void run()
{
Console.WriteLine("je suis laaaaaaaaaaaaaaaaaaaaaaaaa");
while (true)
{
string str = DateTime.Now.ToString("T");
if (str == "08:51:50")
{
Console.WriteLine("cest lheure");
System.Media.SoundPlayer s = new System.Media.SoundPlayer();
s.SoundLocation = "C:\\WINDOWS\\Media\\Windows XP Ouverture de session.wav";
s.Play();

break;
}

}
}


static void Main(string[] args)
{
Console.WriteLine("lancement du thread");
Thread th = new Thread(new ThreadStart(run));
th.Start();


}
}
}
<\code>
merci de votre aide!!

3 réponses

cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 61
7 avril 2006 à 11:06
Essaye de remplacer :

s.Play();

par :

s.PlaySync();


<HR>
[/auteurdetail.aspx?ID=13319
[Pub] ]http://www.csharpfr.com/auteurdetail.aspx?ID=13319 [\Pub]
C# forever /infomsg/auteurdetail.aspx?ID=13319/infomsg/auteurdetail.aspx?ID=13319/infomsg/auteurdetail.aspx?ID=13319
3
cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 61
7 avril 2006 à 10:40
Salut,
Le code suivant fonctionne chez moi :



public
class
Program
{

private
static
void run()
{

while (
true)
{

string str =
DateTime.Now.ToString(
"T");

if (str ==
"10:38:20")
{

Console.WriteLine(
"C'est l'heure");
System.Media.
SoundPlayer s =
new System.Media.
SoundPlayer();
s.SoundLocation =
@"C:\Program Files\messenger\newAlert.wav";
s.Play();

break;
}
}
}



public
static
void Main(
string[] args)
{

Console.WriteLine(
"Lancement du thread");

Thread th =
new
Thread(
new
ThreadStart(run));
th.Start();
}
}

Donc ma question est : as-tu les haut-parleurs allumés?


<HR>
[/auteurdetail.aspx?ID=13319
[Pub] ]http://www.csharpfr.com/auteurdetail.aspx?ID=13319 [\Pub]
C# forever /infomsg/auteurdetail.aspx?ID=13319/infomsg/auteurdetail.aspx?ID=13319
0
cs_othland Messages postés 298 Date d'inscription jeudi 18 décembre 2003 Statut Membre Dernière intervention 9 février 2010 1
7 avril 2006 à 11:26
bien sure que les hauts parleurs sont allumés!!!
au fait, ça marche avec la méthode PlaySync();
merci pour vos réponses!!
0
Rejoignez-nous