cs_pbreaker
Messages postés34Date d'inscriptionsamedi 6 novembre 2004StatutMembreDernière intervention 9 février 2009
-
9 févr. 2009 à 19:25
cs_Bidou
Messages postés5487Date d'inscriptiondimanche 4 août 2002StatutMembreDernière intervention20 juin 2013
-
9 févr. 2009 à 20:09
Bonsoir,
Voila pour être bref je developpe une petite appli pour mon telephone pour lire les flux RSS allociné bref tout vas bien pour la partie download du fichier RSS mais j ai voulu faire joli avec une progressbar pendant le chargement.
le problème avec ça c'est que ya pas moyen d'aprés ce que j'ai trouver pour synchroniser le chargement et l'avancement de la progressbar qu'en passant par les threads. Voila Big problem!
Je sais pas ce qui se passe mais le VS me parle de invoke dont j'ignore complètement l'usage.
Voila mon code qu'est ce qui ne va pas ??
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Threading;
namespace Allocine
{
public partial class Allocine : Form
{
XmlTextReader Lecteur_rss;
XmlDocument Doc_rss;
XmlNode noeud_Rss;
XmlNode noeud_Canal;
XmlNode noeud_Item;
ListViewItem colonne_News;
String lien_actif;
Thread thrd1;
Thread thrd2;
public Allocine()
{
InitializeComponent();
}
//On essay d'etablir la liaison avec le serveur suivant les liens données par le choix de lutilisateur
Lecteur_rss = new XmlTextReader(lien);
//On charge le flux comme etant un document XML
Doc_rss = new XmlDocument();
Doc_rss.Load(Lecteur_rss);
//Nous allons parcourir le document XML à la recherche des noeuds avec la balise <rss>
for (int i = 0; i < Doc_rss.ChildNodes.Count; i++)
{
if (Doc_rss.ChildNodes[i].Name == "rss")
{
noeud_Rss = Doc_rss.ChildNodes[i];
}
}
//Nous allons parcourir le document XML à la recherche des canaux avec la balise <rss>
for (int i = 0; i < noeud_Rss.ChildNodes.Count; i++)
{
if (noeud_Rss.ChildNodes[i].Name == "channel")
{
noeud_Canal = noeud_Rss.ChildNodes[i];
}
}
for (int i = 0; i < noeud_Canal.ChildNodes.Count; i++)
{
// If it is the item tag, then it has children tags which we will add as items to the ListView
if (noeud_Canal.ChildNodes[i].Name == "item")
{
noeud_Item = noeud_Canal.ChildNodes[i];
// Create a new row in the ListView containing information from inside the nodes
colonne_News = new ListViewItem();
colonne_News.Text = noeud_Item["title"].InnerText;
listelement.Items.Add(colonne_News);
}
}
this.thrd2.Abort();
}
public void listelement_SelectedIndexChanged_1(object sender, EventArgs e)
{
// When an items is selected
if (listelement.SelectedIndices.Count == 1)
{
// Loop through all the nodes under <channel>
for (int i = 0; i < noeud_Canal.ChildNodes.Count; i++)
{
// Until you find the node
if (noeud_Canal.ChildNodes[i].Name == "item")
{
// Store the item as a node
noeud_Item = noeud_Canal.ChildNodes[i];
// If the <title> tag matches the current selected item
int h = listelement.SelectedIndices[0];
if (noeud_Item["title"].InnerText.Equals(listelement.Items[h].Text))
{
StringBuilder sb = new StringBuilder();
sb.Append("<html><head></head> " + noeud_Item["description"].InnerText + " </html>");
Contenu.DocumentText = sb.ToString();
break;
}
}
}
}
}
cs_pbreaker
Messages postés34Date d'inscriptionsamedi 6 novembre 2004StatutMembreDernière intervention 9 février 2009 9 févr. 2009 à 19:36
Je reposte le code : désolé encore
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Threading;
namespace Allocine
{
public partial class Allocine : Form
{
XmlTextReader Lecteur_rss;
XmlDocument Doc_rss;
XmlNode noeud_Rss;
XmlNode noeud_Canal;
XmlNode noeud_Item;
ListViewItem colonne_News;
String lien_actif;
Thread thrd1;
Thread thrd2;
public Allocine()
{
InitializeComponent();
}
//On essay d'etablir la liaison avec le serveur suivant les liens données par le choix de lutilisateur
Lecteur_rss = new XmlTextReader(lien);
//On charge le flux comme etant un document XML
Doc_rss = new XmlDocument();
Doc_rss.Load(Lecteur_rss);
//Nous allons parcourir le document XML à la recherche des noeuds avec la balise <rss>
for (int i = 0; i < Doc_rss.ChildNodes.Count; i++)
{
if (Doc_rss.ChildNodes[i].Name == "rss")
{
noeud_Rss = Doc_rss.ChildNodes[i];
}
}
//Nous allons parcourir le document XML à la recherche des canaux avec la balise <rss>
for (int i = 0; i < noeud_Rss.ChildNodes.Count; i++)
{
if (noeud_Rss.ChildNodes[i].Name == "channel")
{
noeud_Canal = noeud_Rss.ChildNodes[i];
}
}
for (int i = 0; i < noeud_Canal.ChildNodes.Count; i++)
{
// If it is the item tag, then it has children tags which we will add as items to the ListView
if (noeud_Canal.ChildNodes[i].Name == "item")
{
noeud_Item = noeud_Canal.ChildNodes[i];
// Create a new row in the ListView containing information from inside the nodes
colonne_News = new ListViewItem();
colonne_News.Text = noeud_Item["title"].InnerText;
listelement.Items.Add(colonne_News);
}
}
this.thrd2.Abort();
}
public void listelement_SelectedIndexChanged_1(object sender, EventArgs e)
{
// When an items is selected
if (listelement.SelectedIndices.Count == 1)
{
// Loop through all the nodes under <channel>
for (int i = 0; i < noeud_Canal.ChildNodes.Count; i++)
{
// Until you find the node
if (noeud_Canal.ChildNodes[i].Name == "item")
{
// Store the item as a node
noeud_Item = noeud_Canal.ChildNodes[i];
// If the <title> tag matches the current selected item
int h = listelement.SelectedIndices[0];
if (noeud_Item["title"].InnerText.Equals(listelement.Items[h].Text))
{
StringBuilder sb = new StringBuilder();
sb.Append("<html><head></head> " + noeud_Item["description"].InnerText + " </html>");
Contenu.DocumentText = sb.ToString();
break;
}
}
}
}
}