5 Replies - 3338 Views - Last Post: 05 June 2011 - 08:48 PM

#1 d.buckner  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 04-December 08

UnauthorizedAccessException when timer ends

Posted 05 June 2011 - 08:12 PM

Yet another in what seems to be a never ending series of problems with my timer. With all of your help, I have been able to get the timer working, and displaying a countdown on the screen like I want. Now, however I am running into an UnautorizedAccesException when the timer ends and I try to execute the next line:

public void MyTimerCallback(object state)
        {

            TextBlock outputBlock = (TextBlock)state;
            if (myCounter >= 0)
            {
                msg = Convert.ToString(myCounter--);

            }
            else
            {
                msg = "END";
                LetterArea.Visibility = System.Windows.Visibility.Collapsed;
                StartButton.Content = "Again?";
                StartButton.Visibility = System.Windows.Visibility.Visible;
            }

            outputBlock.Dispatcher.BeginInvoke(delegate() { outputBlock.Text = msg; });            
        }



The information on the error comes back as a possible security problem? or that I may not have sufficient privileges? I do not understand this error at all.

Is This A Good Question/Topic? 0
  • +

Replies To: UnauthorizedAccessException when timer ends

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: UnauthorizedAccessException when timer ends

Posted 05 June 2011 - 08:16 PM

If I am not mistaken, the callback occurs on a background thread, which is a different thread from where the UI controls are created from. Therefore, you can't access any of the UI controls from this callback unless you do a BeginInvoke.

Let me guess, you get the error on this line...?

LetterArea.Visibility = System.Windows.Visibility.Collapsed;


Was This Post Helpful? 0
  • +
  • -

#3 d.buckner  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 04-December 08

Re: UnauthorizedAccessException when timer ends

Posted 05 June 2011 - 08:19 PM

That's it.....How do I solve it?

I've never used the BeginInvoke.

I thought this would be a good exercise to learn how to program for the Windows Phone, starting to feel like I am no where near ready for this.....

This post has been edited by d.buckner: 05 June 2011 - 08:23 PM

Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: UnauthorizedAccessException when timer ends

Posted 05 June 2011 - 08:22 PM

Using the same code I posted in your thread from 2 weeks ago to fix this same problem.

http://www.dreaminco...ost__p__1344382
Was This Post Helpful? 0
  • +
  • -

#5 d.buckner  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 04-December 08

Re: UnauthorizedAccessException when timer ends

Posted 05 June 2011 - 08:32 PM

I apparently didn't read that part of you post, sorry.

This post has been edited by d.buckner: 05 June 2011 - 08:37 PM

Was This Post Helpful? 0
  • +
  • -

#6 d.buckner  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 04-December 08

Re: UnauthorizedAccessException when timer ends

Posted 05 June 2011 - 08:48 PM

Again, I apologize for this. Not only did I not read your previous post, I also forgot that in my opening animation, my StartButton has been reduced in size to a size that is too small to see. Most of my current problems are my own lack of attention.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1