December 28th, 2011, 03:22 PM
WebBrowser control and timer threads
I am building a C# application that uses the Facebook SDK to poll a person's FB feed periodically for updates. Facebook uses OAuth and I can check to see if a person is logged in upon application startup. The way it works, to log in, the application opens a form with a WebBrowser control which will open the facebook authorization page. If the person grants the app permission, an authorization key is saved. At this point I can periodically check for updates using that key. But if for some reason, the user revokes permission for the app using the FB application authorization page, my application should recognize that by catching an OAuth exception (that works). But what doesn't work is I cannot load the WebBrowser form because this is coming in on a System.Timers.Timer thread. I have found that it will work if I change my timer to a Windows.Forms.Timer, but of course that makes the GUI unresponsive while it is checking the feed for updates. I've also tried using a few different Invokes, but I never got that to work. Googling this returns many pages that suggest adding [STAThread] to the beginning of the Main() program entry, and my app does have that. Can someone show me, in pseudo code, how I can have this WebBrowser control open on System.Timers.Timer thread?
By the way, just to be clear, I am talking about a C# desktop application here, that uses the FB SDK to read a person's FB feed.
January 3rd, 2012, 10:47 PM
Re: WebBrowser control and timer threads
Use the Windows.Forms.Timer and inside the timer event perform the operation within ThreadPool.QueueUserWorkItem.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.