I posted a previous query on this - I have changed the thread calling but I
still have an very odd error

 

I Have a method called from a delegate on a simple button press
Button.Click+=delegate{GetWind(ds);}; 

 

This method checks if the given weather chart has already been downloaded
and saved to sdcard (and is current by its date tag) 

If not it downloads another wx chart and saves that 

 

What seems to happen is that it runs through the GetWind() routine twice and
encounters a sharing violation  or sometimes a java.land throw exception and
sometimes simply unhandled exception 

 

Usually happens when trying to save the bitmap (the save method is nothing
special - 

 WXclass5.windmap.Compress(Bitmap.CompressFormat.Png, 85, new
System.IO.FileStream(filename,FileMode.Create)); 

 

 

What seems to happen on stepping through debug is that it steps around a
second time and calls this save method twice and it is on this second time
around that the exception occurs

 

<Sri> has suggested that this might be due to running on several threads

I did call this method using   ThreadPool.QueueUserWorkItem(o =>
GetWind(ds));

But I have taken that out (see below I have commented out UI lines 

SO there is no calling threads (as far as I can see ) 

 

Can anyone explain why this code doesn't work 

 

 

private void GetWind(string ds)     // ds is a date and time stamp for a
given wx chart

        {

                string filename = "";

                string mystr = this.GetFileStreamPath("").ToString();

                filename = mystr + "/wmap" + WXclass5.altsel + "#" + ds +
"$" + WXclass5.windmapexpires + ".png";     

                                int rtn =
WXclass5.checksavedwindmap(this,filename);

                                if ( rtn < 0)

                {

                    try

                    {

                     WXclass5.getwindmap(ds, WXclass5.altsel.ToString());

                    filename = mystr + "/wmap" + WXclass5.altsel + "#" + ds
+ "$" + WXclass5.windmapexpires + ".png";

                     WXclass5.saveBMP(this,filename);

                    }catch(System.Exception xe)

                                    { Toast.MakeText(this, "Error load wx
wind \n" + xe.Message, ToastLength.Long).Show();      }

                                }

                                else

                                {

                                                filename =
mystr+"/"+WXclass5.pnglist[rtn];

                                                FileStream fs = new
FileStream(filename, FileMode.Open, FileAccess.Read);

                                System.IO.BufferedStream buf = new
System.IO.BufferedStream(fs);

                                bm = BitmapFactory.DecodeStream(buf);

                                                    if (fs != null) 

                                                                    {

                                                                fs.Close();

                                                    }

                                            if (buf != null) 

                                                                    {

                                                buf.Close();

                                            }                  

                                WXclass5.windmap = bm; 

                                filename="";

                                }

 


        // RunOnUiThread( () =>t1.Text = WXclass5.getaltstring());

                //            RunOnUiThread( () =>
t1.SetBackgroundColor(Color.Transparent));

                //            RunOnUiThread( () =>   t1.TextSize=16);


        //RunOnUiThread( () =>i1.ImageMatrix.Set(mm));                  

        //RunOnUiThread( () =>i1.SetImageBitmap(WXlass5.windmap));

                //RunOnUiThread( () =>pb.Visibility=ViewStates.Invisible);

                                                

                                                i1.ImageMatrix.Set(mm);

 
i1.SetImageBitmap(WXclass5.windmap);

 
pb.Visibility=ViewStates.Invisible;            

     }

 

 

Any help would e much appreciated - been stuck on this for several days now

John Murray

_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to