473,382 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

App "Freezes" when getting atom feed

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);
}
}
}

}

Feb 6 '06 #1
15 2286
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]
- mv*@spam.guard.caspershouse.com
"Brady Love" <op******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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);
}
}
}

}

Feb 6 '06 #2
Thank you for your reply, Do you know of any good online tutorials that
would show how I would do this?

Thanks again.

Feb 6 '06 #3
I figured out how to create the thread and use it. But the problem is
now as you mentioned, updating the UI.

" 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. "

Do you have any tutorials on that?

Feb 6 '06 #4
In your simple example, a call to Application.DoEvents would be
sufficient.

Feb 6 '06 #5
Brady,

I don't have one offhand, but here is an example.

Say you needed to update the Text property of a control with a string
generated/retrieved in the thread. Create a method to do it, like this:

private void UpdateText(string val)
{
// Set the text.
textControl.Text = val;
}

Now, create a delegate with the same signature:

delegate void UpdateTextDelegate(string val);

Then, in your thread, you would do this:

// Call UpdateText on the UI thread.
textControl.Invoke(new UpdateTextDelegate(UpdateText), new
object[]{someString});
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brady Love" <op******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I figured out how to create the thread and use it. But the problem is
now as you mentioned, updating the UI.

" 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. "

Do you have any tutorials on that?

Feb 6 '06 #6
And it would also be horribly wrong...

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chris Dunaway" <du******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
In your simple example, a call to Application.DoEvents would be
sufficient.

Feb 6 '06 #7
Hi,

"Chris Dunaway" <du******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
In your simple example, a call to Application.DoEvents would be
sufficient.


And wrong too, the correct way is to create a thread and do the processing
there. Calling DoEvents can provoke some very funky problems, very hard to
solve !

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Feb 6 '06 #8
It seems to still freeze up for a second, here is the code I have now:

delegate void getBlogsDelegate();

protected void getBlogs()
{
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", "pass");

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)
{

this.blogSet.Blogs.AddBlogsRow(entry.id.ToString() ,
entry.title.ToString(), entry.issued.ToString(),
entry.author.ToString(), entry.contentValue.Text);
}
}
}
}

private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
{

td = new Thread(new ThreadStart(doGetBlogs));
td.Start();
}

private void doGetBlogs()
{
lstBlogs.Invoke(new getBlogsDelegate(getBlogs));
}

Is this the correct usage of the delegate and thread? Im not so sure (I
am very beginner at progoramming and threads are all new to me today)
Thanks again for your help.

Feb 6 '06 #9
Brady,

No, this is not. You don't want to call Invoke in your thread to
perform the whole operation, because this will cause the operation to just
be executed in the UI thread, which is the problem in the first place.

Rather, you want to call Invoke in your thread when you make this call:
this.blogSet.Blogs.AddBlogsRow(entry.id.ToString() ,
entry.title.ToString(), entry.issued.ToString(),
entry.author.ToString(), entry.contentValue.Text);
Because that seems to be the only thing updating the UI.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Brady Love" <op******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com... It seems to still freeze up for a second, here is the code I have now:

delegate void getBlogsDelegate();

protected void getBlogs()
{
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", "pass");

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)
{

this.blogSet.Blogs.AddBlogsRow(entry.id.ToString() ,
entry.title.ToString(), entry.issued.ToString(),
entry.author.ToString(), entry.contentValue.Text);
}
}
}
}

private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
{

td = new Thread(new ThreadStart(doGetBlogs));
td.Start();
}

private void doGetBlogs()
{
lstBlogs.Invoke(new getBlogsDelegate(getBlogs));
}

Is this the correct usage of the delegate and thread? Im not so sure (I
am very beginner at progoramming and threads are all new to me today)
Thanks again for your help.

Feb 6 '06 #10
How would I do that? I am having trouble understanding where it goes
exactly and what it the line of code should be. Sorry to be a pain.

Feb 6 '06 #11
I found this example, is this what you are talking about?

http://msdn2.microsoft.com/a1hetckb(en-US,VS.80).aspx

Feb 6 '06 #12
Brady,

Yes, it is.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brady Love" <op******@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
I found this example, is this what you are talking about?

http://msdn2.microsoft.com/a1hetckb(en-US,VS.80).aspx

Feb 7 '06 #13
Okay I will see if i can get this working, Thanks.

Feb 7 '06 #14
SP

"Brady Love" <op******@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
I found this example, is this what you are talking about?

http://msdn2.microsoft.com/a1hetckb(en-US,VS.80).aspx


If you are using .Net 2.0 there is a BackgroundWorker object that you should
take a look at.

SP
Feb 7 '06 #15
Yay I did it! I was totally using the delegate completely wrong. This
is the document that helped me figure it out if anyone else is in the
same boat I was.

http://www.agiledeveloper.com/articl...oundWorker.pdf

Thanks again for all your guys help and pointing me in the right
direction.

Feb 7 '06 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Scott Beavers | last post by:
I'm trying to create a form in Excel to sort from the form and take the data to another worksheet. I am very new to this and any help would be appreciated. I have a value in a cell that will...
5
by: Basil Fenix | last post by:
I check data from a text file with a mdb Database using a progressbar and changing the Caption by % to indicate to the user what is happening.The file is large and takes quite a while. The problem...
1
by: Aaron Davies | last post by:
I'm developing a collaborative whiteboard, in which all objects (shapes, clip art icons, etc.) are synchronized between all participants in a session. It's working well, but I'm running into a...
12
by: beliavsky | last post by:
I just came across the slides for Guido van Rossum's "Python Regrets" talk, given in 2002. It worries me that much of my Python code would be broken if all of his ideas were implemented. He doesn't...
2
by: oopaevah | last post by:
I am using the Microsoft.XMLHTTP object to make server requests ie; ajax. This is working 99% of the time but occasionally it will freeze at the server for 5 minutes and then raise a javascript...
2
by: Dvinb1234 | last post by:
I get this message when i try to start any type of internet (aol, internet explorer, mozilla) and my computer lags up likw crazy and then "Not Responding" then turns off but every other problem works...
2
by: Ronald S. Cook | last post by:
In my Windows app, when you click to load a form, it kind of draws part of some controls as it's doing other things and then finally draws everything. This looks bad. Is there a way I can just...
0
by: Burton Roberts | last post by:
This is my first Windows Client - WCF program. I'm generally following the pattern shown in Beth Massi videos and developing with VS2008 and SQL Server 2008. I have completed a simple application...
8
joedeene
by: joedeene | last post by:
Hello there, I am having a problem and it is frustrating me because I've been trying to figure it out, and I've even modified the code a few times but the same exception occurs: "...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.