Q:

System. UnauthorizedAccessException with text-to-speech in Windows Phone 8

I have the following piece of code for using text to speech feature in Windows Phone 8.  I am using ssml, with bookmarks.  But when changing any UI element in the Bookmark event called function, raises Unauthorized Exception. 
private void Initialise_synthesizer()
        {
            this.synthesizer = new SpeechSynthesizer();

            synthesizer. BookmarkReached += new TypedEventHandler<SpeechSynthesizer, SpeechBookmarkReachedEventArgs>
                (BookmarkReached);
        }

void BookmarkReached(object sender, SpeechBookmarkReachedEventArgs e)
        {
            Debugger. Log(1, "Info", e.Bookmark + " mark reached\n");

            switch (e.Bookmark)
            {
                case "START":
                    cur = start;
                    break;
                case "LINE_BREAK":
                    cur++;
                    break;
                }
**error here**  t1.Text = cur. ToString();
            }

But on running it gives the following error
A first chance exception of type 'System. UnauthorizedAccessException' occurred in System.Windows.ni.dll
An exception of type 'System. UnauthorizedAccessException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary
Invalid cross-thread access. 

Any idea how to fix this error, or any work around. 

A:

Just got the answer. 
Since the synthesizer. SpeakSsmlAsync() is an async function, to perform UI operations Dispatcher has to be used, something like this -
Dispatcher. BeginInvoke(() =>
                t1.Text = cur. ToString());

