That's just it Sri 
All I have is ButtonClick+=delegate{GetWind(ds);};

Getwind(ds) is called again only from different buttons which are not
involved in this process
There's no other eventhandler attached to this particular  button 

Are you saying that if One defines the event handler as a delegate in the
above way it will call it twice? 

Still puzzled but Tx hugely for responding 
Beginning to think I should rename it PassWind() :-) 

John Murray 


-----Original Message-----
From: SRI [mailto:sri...@gmail.com] 
Sent: 25 September 2011 2:49 PM
To: j...@murray.gb.com; Discussions related to Mono for Android
Subject: Re: [mono-android] sharing violation and a method which seems to
run twice

HI,

       Are you attaching two times the event Handlers to the Button
Click. Basically is
       is this call Button.Click+=delegate{GetWind(ds);} executed twice.

       Then also this method (GetWind(ds) will execute twice.

Best Regards,
Sridharan Srinivasan
Alias Sri

On Sun, Sep 25, 2011 at 4:23 AM, John Murray <j...@murray.gb.com> wrote:
> 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
> Monodroid@lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>
>



-- 
Sridharan Srinivasan
Alias Sri
Ph:(65)98255785/(65)63922439
www.arshu.com
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

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

Reply via email to