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 !