C# foreach

C

can320

Gast
Mit der Beta Version von Visual Studio 2005 hat der folgende Quellcode bestens Funktioniert.
Code:
           foreach (Label l in grpTest.Controls)
            {

                    l.Text = "";
            }
Jetzt meldet es mir:
Unable to cast object of type 'System.Windows.Forms.ComboBox' to type 'System.Windows.Forms.Label'.
 
can320 schrieb:
Unable to cast object of type 'System.Windows.Forms.ComboBox' to type 'System.Windows.Forms.Label'.

Moin,
da stimmt eindeutig was nicht mit deinen Typen in deiner Gruppe.
Hast Du da verschiedene Elemente drin?
Ne ComboBox die er nicht in ein Label umwandeln kann?
 
Oh ja mein Fehler, habs doch glatt übersehen :(


Die Meldung ist aber wirklich neu:
A call to PInvoke function 'Prog!Prog.Form1::PlaySound' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

Ich Spiele eine Sound Datei insgesammt 5 mal in einem neuen Thread ab. Nachdem der Sound ein mal abgespielt wurde kommt die Meldung.
for (int i = 0; i < 5; i++)
PlaySound(Application.StartupPath + "/test.wav", 0, 0);
 
Hi can320,
leider kann ich Dir bei deinem neuen Problem nicht weiterhelfen,
evtl. könnte es Dir helfen wenn Du in deiner FOR-Schleife ein Thread.Sleep( Zeit in ms ) einfügst.
Schau mal auf www.codeproject.com dort findest Du bestimmt ein ähnliches Projekt, dass Dir weiterhilft.

Grüsse,
Pete
 
Das mit dem Sleep ist ein Ansatz, wenn ich die Fehlermeldung aber richtig verstehe, sollte das Sleep solange gehen bis PlaySound fertig ist mit dem abspielen.

D.h. probier mal das aus, ob es dann geht:

Code:
PlaySound(Application.StartupPath + "/test.wav", 0, SND_SYNC);

MfG

Arnd
 
Zurück
Oben