Hi!
I keep getting an Android.Util.AndroidRuntimeException when running my program on my Android phone. I am trying to run a simple program which basically runs a loop inside an async block when a button is pressed. The loop is supposed to use the Event.Trigger function each iteration to update a textbox with the current iteration. And it is when Event.Trigger is used that i get the exception.
In AsyncTest.fs:
let runAsyncLoop (ev:Event<string>) =
ev.Trigger "Pre async" //This causes no exception
async {
for i in [1..10] do
ev.Trigger ("Iteration: " + i.ToString()) //Error here
do! Async.Sleep 1000
}
let runAll (ev:Event<string>) =
Async.Start (runAsyncLoop ev)
"Async started!"
In MainAcitivity.fs:
let textBox = this.FindViewById<TextView>(Resource_Id.asyncStatus)
let updateTextBox s = textBox.Text <- sprintf "%s" s
let ev = new Event<string>()
ev.Publish.Add(updateTextBox)
let toggle = this.FindViewById<ToggleButton>(Resource_Id.asyncToggle)
toggle.Click.Add (fun _ ->
if toggle.Checked
then let s = runAll ev
textBox.Text <- sprintf "%s" s
else cancelSource.Cancel()
)
The whole 'trigger inside async' works fine when just running it on my pc so I thought there might be some known problems with this combination on Android. Or maybe it is just my program that fails. Either way I hope you will be able to help
Cheers!