This project is read-only.

Trying to use the controls and I am getting Invalid Cross-Thread access

Apr 28, 2014 at 5:20 PM
Good afternoon. I am trying to use the controls for the first time in a WP7 app to display the better Toast notification. I am having an issue with it, I am getting Invalid Cross-Thread access when I dim it within my background task using Dim toast As New ToastPrompt. I am importing Coding4Fun.dll as reference and using Imports Coding4Fun.Phone.Controls. Can anyone tell me what else I may need to be doing, I am having such an issue and know it is all on my end, but just cannot figure out where I am messing up.

Thanks a bunch for your help!
Apr 28, 2014 at 5:28 PM
if you are using Coding4Fun.Phone, name space, you're using a much older version of the toolkit.

I'm betting if you upgrade to the newest, this issue will go away. If not, since you're calling this on a background thread, you'll need to Dispatcher.BeginInvoke on the call.
Apr 28, 2014 at 5:32 PM
I have the latest, but I am new to using custom controls via dll's in my apps. How should I use it? should I omit the imports call or is there some other step I am missing?

I really appreciate your help!
Apr 28, 2014 at 6:21 PM
Ok, I have just found some steps to install this and now I am using Dim toast As New Controls.ToastPrompt but I am still getting the same error. You mentioned would I use that? Is that done on the Dim? I am a bit consfused with it. Sorry.

Thanks again,
Apr 29, 2014 at 3:38 AM
Be warned, I'm much more of a C# developer so hopefully this translation is correct.

Dim toast As New ToastPrompt()

toast.Title = "Hello"
toast.Message = "World"
toast.ImageSource = New BitmapImage(New Uri("ApplicationIcon.png", UriKind.RelativeOrAbsolute))
Catch exception As Exception
End Try

End Function)
Apr 29, 2014 at 4:10 PM
Thank you a bunch! Sometimes I feel like I am an idiot when it comes to some of this stuff, I have been coding a long time and when it comes to this I just do not get it. I have placed the code in and have tried a bunch of variations including Deployment.Current.Dispatcher.BeginInvoke but it just does not want to work for me, now I am getting a "exception = {"Reference is not a valid visual DependencyObject."}" error....I have no idea what I can attach the dispatcher to that will allow it to work. I have had trouble in the past adding other custom controls. I think it has to do with trying to do this in VB most of the time and being so weak in C# that it makes it hard to convert the code myself. I may just have to abandon trying to do it this way since it is obviously something I just cannot grasp.

Thanks a bunch for your help!!
Apr 29, 2014 at 7:44 PM
I would really need to see a sample project with what you're trying to accomplish. Can you create a work item with a zipped solution that I can attach a debugger against and steps to reproduce?
Apr 30, 2014 at 4:24 AM
Sure, I can zip the entire thing up or would you prefer a simplified version, although it is kind of a simple app anyway. Just a simple weather app that grabs weather from my website and displays it, but also has tile updating and am trying the toast stuff for alerts. How would I make a work item? I appreciate your help!! I can also email it or place it on my website for you to download. It is entirely up to you.

Thanks again,
Apr 30, 2014 at 5:08 AM
Simplified version that reproduces the issue
Apr 30, 2014 at 2:05 PM
Ok, I have simplified it down to just the background task being called and the code gets fired within the background task now. It fires every minute or so. When the background task fires and the following code is executed toast2.Show() it bugs out with the exception "{"Reference is not a valid visual DependencyObject."}" which I guess makes sense since it is not running within a UI, or at least that is the impression I get after trying to make it work and trying to find an answer. I appreciate your help very much!!

How can I get the zip to you? You said create a work item? I can also give a link to download from my site or I can share in onedrive etc?

Thanks a bunch,
Apr 30, 2014 at 3:14 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Apr 30, 2014 at 3:15 PM
Apr 30, 2014 at 3:19 PM
Thank you very much...I have placed it on the work item.