Ma requête concerne environ BackgroundWorker
.Utilisation de l'arrière-plan dans une application multithread
J'ai une application Windows Forms qui démarre 10 nouveaux threads. Chaque thread recevra des informations de 10 services Web différents. Tout ce dont j'ai besoin est d'ajouter le résultat d'un appel de service web dans une boîte de texte riche placée en mode design. Comment puis-je utiliser le thread d'arrière-plan dans ce scénario?
ArrayList threadList;
for (int idx = 0; idx < 10; ++idx)
{
Thread newth= new Thread(new ParameterizedThreadStart(CallWS));
threadList.Add(newth);
}
for (int idx = 0; idx < 10; ++idx)
{
Thread newth= new Thread(new ParameterizedThreadStart(CallWS));
newth.Start(something);
}
for (int idx = 0; idx < 10; ++idx)
{
//Cast form arraylist and join all threads.
}
private void CallWS(object param)
{
// Calling WS
// got the response.
// what should I do to append this to rich text box using background worker.
}
Toute aide très appréciée.
Nous sommes en 2011. Pourquoi utilisez-vous 'ArrayList' au lieu de' List '? En outre, votre code n'a pas de sens. Pourquoi créez-vous 10 threads, puis commencez 10 threads complètement différents? –
svick
Le code n'utilise pas le composant BackgroungWorker et le thread n'a pas de sens. –