Hi JP
Working the weekend again I see - is there no end to your dedication !
But a thousand tx for yr attention 

I've detached all the code into a simple Android buttonclick demo 
(pretty much how it all works in my app - it is called as a separate
activity )
It demonstrates the same issue of going through the GetWind(ds) method twice

Outlining - there is a form with 4 buttons and one spinner
Getwind() is called from each as delegate 
I can see there might be a problem is someone hammered all the buttons at
once but the issue arises if you ignore all but say the right hand button
(which increments the date) and press it clearly once and step through in
debugger

Surely it can't be that you can't have different buttons calling the same
method for fear it will run twice?

Best regards
John M





-----Original Message-----
From: Jonathan Pryor [mailto:[email protected]] 
Sent: 25 September 2011 15:24
To: [email protected]; Discussions related to Mono for Android
Cc: 'SRI'
Subject: Re: [mono-android] sharing violation and a method which seems to
run twice

I think at this point we'll need a complete sample, so that we can see
how/where the GetWind() method is invoked. It's also possible that this is a
bug in Mono for Android, so filing a complete test case at
bugzilla.xamarin.com would help. :-)

 - Jon

On Sep 25, 2011, at 10:13 AM, John Murray wrote:

> 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:[email protected]] 
> Sent: 25 September 2011 2:49 PM
> To: [email protected]; 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 <[email protected]> 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
>> [email protected]
>> 
>> UNSUBSCRIBE INFORMATION:
>> http://lists.ximian.com/mailman/listinfo/monodroid
>> 
>> 
> 
> 
> 
> -- 
> Sridharan Srinivasan
> Alias Sri
> Ph:(65)98255785/(65)63922439
> www.arshu.com
> _______________________________________________
> Monodroid mailing list
> [email protected]
> 
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid


_______________________________________________
Monodroid mailing list
[email protected]

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

Reply via email to