Re: App "Freezes" when getting atom feed



Brady,

Are you doing this in response to a UI event, like a button click? If
you are, chances are you are running the code on the UI thread.

To make a long story short, when your program runs, it processes
messages in a loop for the length of the program. These messages are sent
to and from windows to tell them when to do things, and send notifications.

Now, when you write code in response to a button click, your code has to
process before any more messages can be processed. This is what is causing
the "freezing".

To get around this, you would want to run the code in another thread.
This is quite simple to do. However, what you have to be careful of is when
you want to send notifications back to the thread (i.e. update the UI). You
can't make calls to do this from the thread you did the downloading from.

In order to do this, you have to create a method which will perform your
UI work. You then have to create a delegate which shares the signature of
your method. Then, from your UI thread, you can call the Invoke method on a
control, passing the delegate (pointing to your UI update method) and your
parameters. The method will then invoke the delegate passed in and then
invoke it on the UI thread.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx


"Brady Love" <opettaja@xxxxxxxxx> wrote in message
news:1139248834.524139.191190@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am currently working an an app that will post and edit blogs on
blogger. Right now I have it so I can recive a list of the blogs and
the content of those blogs using Atomizer. This is my first program
where I am accessing data over the net.When I go to retrieve the list
of blogs my program acts like it is locked up/frozen for a few seconds
and then when it is done it goes back to normal. Does anyone know how I
would get rid of the freezing? Here is the code where the freeze
occurs.

public void getBlogs(string[] args)
{
string atomEndPoint = "https://www.blogger.com/atom/";;

generatorType generator = new generatorType();
generator.url = "http://www.mywebsite.com";;
generator.Value = "myappname";
generator.version = "0.1";

Atom atom = Atom.Create(new Uri(atomEndPoint), generator,
"username", "password");

service[] services = atom.GetServices();


foreach (service service in services)
{
if (service.srvType.Equals(serviceType.feed))
{

feedType feed = atom.GetFeed(service.postURL);

foreach (entryType entry in feed.entries)
{
blogSet.Blogs.AddBlogsRow(entry.id.ToString(),
entry.title.ToString(), entry.issued.ToString(),
entry.author.ToString(), entry.contentValue.Text);
}
}
}

}



.