begin process at 2010 02 10 04:41:52
  Trouver un code source :
 
dans
 
Accueil > Forum > 

C#

 > 

Mono

 > 

Général

 > 

NullReferenceException lors d'un AsyncCallback


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

NullReferenceException lors d'un AsyncCallback

vendredi 25 avril 2008 à 20:56:55 | NullReferenceException lors d'un AsyncCallback

AmK


Bonsoir,

je désire faire un appel asynchrone vers un webservice mappoint, j'opère donc de la manière suivante:

[code]
   Stream imageStream; // variable globale
   void DisplayMap(double latitude,double longitude)
   {
       // du code...
       RenderServiceSoap rss;
       rss.BeginGetMap(mapSpecif, new AsyncCallback(GetMapThread), rss);
   }

         private void GetMapThread(IAsyncResult state)
        {
            RenderServiceSoap rss = state.AsyncState as RenderServiceSoap;
            if (rss == null)
                return;
            MapImage[] images = rss.EndGetMap(state);
            imageStream = new System.IO.MemoryStream(images[0].MimeData.Bits);

        }

       // puis au niveau de ma fct principale
       DisplayMap(pos_lat,pos_long);
       pictureBox1.Image=new System.Drawing.Bitmap(imageStream); //la varia ble globale devrait être mis à jour à l'intérieur de GetMapThread
[/code]

A l'execution j'obtiens une exception de type NullReferenceException, donc voici le détail :
[quote]
        StackTrace    "   at System.Drawing.Bitmap..ctor(Stream stream)\r\n   at PickMeUp.RiderStartSearch..ctor()\r\n   at PickMeUp.RiderMainMenu.startsearch_SelectedIndexChanged(Object sender, EventArgs e)\r\n   at System.Windows.Forms.ListView.OnSelectedIndexChanged(EventArgs e)\r\n   at System.Windows.Forms.ListView.UpdateSelectedIndex(Int32 iItem)\r\n   at System.Windows.Forms.ListView.WnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at Microsoft.AGL.Forms.EVL.EnterModalDialog(IntPtr hwnModal)\r\n   at System.Windows.Forms.Form.ShowDialog()\r\n   at PickMeUp.SelectMode.RiderMode_SelectedIndexChanged(Object sender, EventArgs e)\r\n   at System.Windows.Forms.ListView.OnSelectedIndexChanged(EventArgs e)\r\n   at System.Windows.Forms.ListView.UpdateSelectedIndex(Int32 iItem)\r\n   at System.Windows.Forms.ListView.WnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at Microsoft.AGL.Forms.EVL.EnterModalDialog(IntPtr hwnModal)\r\n   at System.Windows.Forms.Form.ShowDialog()\r\n   at PickMeUp.FLogin.Login_Click(Object sender, EventArgs e)\r\n   at System.Windows.Forms.Control.OnClick(EventArgs e)\r\n   at System.Windows.Forms.Button.OnClick(EventArgs e)\r\n   at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)\r\n   at System.Windows.Forms.Application.Run(Form fm)\r\n   at PickMeUp.Program.Main()\r\n"    string
[/quote]

Ce qui est bizarre c'est qu'un coup j'obtiens ça, un coup j'obtiens un NullReferenceException mais avec un message comme quoi je devrais utiliser Invoke..
[quote]"Control.Invoke must be used to interact with controls created on a separate thread."    string[/quote]
Je tiens à signaler que j'ai tenté d'utiliser un delegate de la manière suivante :

[code]
        private delegate void GetMapThreadDelegate(IAsyncResult state);
        private void DoUpdate2(IAsyncResult state)
        {

            if (this.InvokeRequired)
            {
    
                this.Invoke(new GetMapThreadDelegate(DoUpdate2),new object[] { state });
                return;
            }
        
            MapImage[] images = rss.EndGetMap(state);
            imageStream = new System.IO.MemoryStream(images[0].MimeData.Bits);

        }
[/code]

Avec la mise à jour effectuée dans GetMapThread ( qui appelle la méthode DoUpdate2 )

J'ai cherché sur le net de l'aide sur ce genre de msg d'erreur apparemment c'est assez connu comme problème, mais je n'ai pas su adapter les solutions trouvées à mon cas :(

Merci pour votre aide grandement appréciée !
vendredi 25 avril 2008 à 21:03:22 | Re : NullReferenceException lors d'un AsyncCallback

AmK

PS:desolé pour la mise en forme j'étais pas au courant que les balises quote et code ne fonctionnaient pas ici, et pas moyen d'éditer apparemment ?  Je reposte en ajoutant des couleurs ^^

Bonsoir,

je désire faire un appel asynchrone vers un webservice mappoint, j'opère donc de la manière suivante:

   Stream imageStream; // variable globale
   void DisplayMap(double latitude,double longitude)
   {
       // du code...
       RenderServiceSoap rss;
       rss.BeginGetMap(mapSpecif, new AsyncCallback(GetMapThread), rss);
   }

         private void GetMapThread(IAsyncResult state)
        {
            RenderServiceSoap rss = state.AsyncState as RenderServiceSoap;
            if (rss == null)
                return;
            MapImage[] images = rss.EndGetMap(state);
            imageStream = new System.IO.MemoryStream(images[0].MimeData.Bits);

        }

       // puis au niveau de ma fct principale
       DisplayMap(pos_lat,pos_long);
       pictureBox1.Image=new System.Drawing.Bitmap(imageStream); //la varia ble globale devrait être mis à jour à l'intérieur de GetMapThread


A l'execution j'obtiens une exception de type NullReferenceException, donc voici le détail :

        StackTrace    "   at System.Drawing.Bitmap..ctor(Stream stream)\r\n   at PickMeUp.RiderStartSearch..ctor()\r\n   at PickMeUp.RiderMainMenu.startsearch_SelectedIndexChanged(Object sender, EventArgs e)\r\n   at System.Windows.Forms.ListView.OnSelectedIndexChanged(EventArgs e)\r\n   at System.Windows.Forms.ListView.UpdateSelectedIndex(Int32 iItem)\r\n   at System.Windows.Forms.ListView.WnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at Microsoft.AGL.Forms.EVL.EnterModalDialog(IntPtr hwnModal)\r\n   at System.Windows.Forms.Form.ShowDialog()\r\n   at PickMeUp.SelectMode.RiderMode_SelectedIndexChanged(Object sender, EventArgs e)\r\n   at System.Windows.Forms.ListView.OnSelectedIndexChanged(EventArgs e)\r\n   at System.Windows.Forms.ListView.UpdateSelectedIndex(Int32 iItem)\r\n   at System.Windows.Forms.ListView.WnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at Microsoft.AGL.Forms.EVL.EnterModalDialog(IntPtr hwnModal)\r\n   at System.Windows.Forms.Form.ShowDialog()\r\n   at PickMeUp.FLogin.Login_Click(Object sender, EventArgs e)\r\n   at System.Windows.Forms.Control.OnClick(EventArgs e)\r\n   at System.Windows.Forms.Button.OnClick(EventArgs e)\r\n   at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)\r\n   at System.Windows.Forms.Application.Run(Form fm)\r\n   at PickMeUp.Program.Main()\r\n"    string


Ce qui est bizarre c'est qu'un coup j'obtiens ça, un coup j'obtiens un NullReferenceException mais avec un message comme quoi je devrais utiliser :Invoke.

"Control.Invoke must be used to interact with controls created on a separate thread."    string
Je tiens à signaler que j'ai tenté d'utiliser un delegate de la manière suivante :


        private delegate void GetMapThreadDelegate(IAsyncResult state);
        private void DoUpdate2(IAsyncResult state)
        {

            if (this.InvokeRequired)
            {
    
                this.Invoke(new GetMapThreadDelegate(DoUpdate2),new object[] { state });
                return;
            }
        
            MapImage[] images = rss.EndGetMap(state);
            imageStream = new System.IO.MemoryStream(images[0].MimeData.Bits);

        }



Avec la mise à jour effectuée dans GetMapThread ( qui appelle la méthode DoUpdate2 )

J'ai cherché sur le net de l'aide sur ce genre de msg d'erreur apparemment c'est assez connu comme problème, mais je n'ai pas su adapter les solutions trouvées à mon cas :(

Merci pour votre aide grandement appréciée !


Cette discussion est classée dans : windows, system, forms, int32, at


Répondre à ce message

Sujets en rapport avec ce message

Problème de chargement d'une image [ par kyfranBibax ] Coucou, En fait, j'ai une pictureBox qui doit prendre une image. Aucun problème avec la plupart d'entre elles sauf avec une qui est en tif et qui fai Erreur à la dépose d'un ActiveX sur la form ( sur Borland C# Personnel ) [ par lefter ] * L'erreur suivante s'affiche lorsque je dépose d'un ActiveX sur la form:Impossible d'ajouter une référence à la bibliothèque de types ActiveX. Vérifi Problème activex avec C#builder personnel [ par blaforge ] * L'erreur suivante s'affiche lorsque je dépose d'un ActiveX sur la form: Impossible d'ajouter une référence à la bibliothèque de types ActiveX. Véri Message d'erreur [ par taoetc ] Bon je bloque sur un message d'erreur qui bien sur me plante mon appli sévére. Alors je sais , c'est pas évident de voir d'où ca vient vu que vous ave Constructeur IPAdress [ par Xdjibi ] Bonsoir, Je lutte un peu (doux euphémisme!) avec le constructeur de la classe IPAddress. MSDN Library donne trois constructeurs pour IPAddress : Problème dll au déploiement [ par coinki ] Salut,J'ai fait un petit programme en C# dans lequel j'ai lié une dll en faisant Project>AddReference>com.Sur mon poste tout est nickel !!J'ai essayé pb commande dos [ par penchu ] bonjour à tous, je fais un petit prog pour comprendre l'exécution de commande dos. c'est un prog pour envoyer des messages avec la commande net sen Probleme à l'exportation de ma programme [ par fcolo ] Bonjours,je viens de réaliser une mini application (un condensé de la vrai) pour essayer de savoir comment faire tourner mon programme sur d'autres PC Taille Maximale d'un controle ???? [ par tservolle ] Bonjour,Savez vous si il existe une limite maximale pour la taille d'un controle dans un Winform ???En fait je suis en train d'écrire un controle qui Hook clavier [ par iow4 ] Bonjour, J'ai trouvé sur le site de microsoft un exemple qui permeté de mettre en place un hook sur la souris, j'ai essayé de le modifié pour faire un


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,014 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales