应用程序“冻结”当得到原子进料 [英] App "Freezes" when getting atom feed

查看:68
本文介绍了应用程序“冻结”当得到原子进料的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一款可以在

博客上发布和编辑博客的应用。现在我拥有它,所以我可以使用Atomizer查看博客列表和

这些博客的内容。这是我的第一个程序

,我通过网络访问数据。当我去检索列表

的博客我的程序就像被锁定/冻结几秒钟

然后当它完成后它会恢复正常。有谁知道我怎么会b / b
摆脱冻结?以下是冻结

的代码。

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(服务中的服务)

{

if(service.srvType.Equals(serviceType.feed))

{


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


foreach(feed.entries中的entryType条目)

{

blogSet.Blogs.AddBlogsRow(entry.id。 ToString(),

entry.title.ToString(),entry.issued.ToStrin g(),

entry.author.ToString(),entry.contentValue.Text);

}

}

}


}

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

}

推荐答案

Brady,


您是否这样做是为了响应UI事件,例如点击按钮?如果你是b $ b,那么你很有可能在UI线程上运行代码。


总而言之,当程序运行时,它会处理

循环中的消息,用于程序的长度。这些消息是从windows发送给b
告诉他们什么时候做的事情,并发送通知。


现在,当你编写代码来回应按钮单击,您的代码必须

进程才能处理更多消息。这就是导致

冻结的原因。

为了解决这个问题,你需要在另一个线程中运行代码。

这很简单。但是,您需要注意的是,当您想要将通知发送回线程时(即更新UI)。你不能通过你下载的帖子拨打电话来做这件事。


为了做到这一点,你必须创建一个将执行您的UI
UI工作的方法。然后,您必须创建一个委托,该委托与您的方法共享

的签名。然后,从您的UI线程,您可以在

控件上调用Invoke方法,传递委托(指向您的UI更新方法)和您的

参数。然后该方法将调用传入的委托,然后

在UI线程上调用它。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv * @ spam.guard.caspershouse.com

" Brady Love" <运算****** @ gmail.com>在消息中写道

news:11 ********************** @ g14g2000cwa.googlegr oups.com ...
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...
我目前正在开发一个应用程序,用于在博客上发布和编辑博客。现在我拥有它,所以我可以使用Atomizer查看博客列表和
这些博客的内容。这是我的第一个程序
我通过网络访问数据。当我去检索博客列表时,我的程序就像锁定/冻结几秒钟一样
然后当它完成后它恢复正常。有谁知道我怎么会摆脱冻结?以下是冻结
的代码。

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(服务中的服务)
{
if(service.srvType.Equals(serviceType.feed))
{

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

foreach(feed.entries中的entryType条目)
{
blogSet.Blogs.AddBlogsRow(entry.id.ToString(),
entry.title.ToString(),entry.issued.ToString(),
entry.author.ToString(),条目。 contentValue.Text);
}
}

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

}



谢谢对于你的回复,你知道任何好的在线教程

会显示我会怎样做吗?


再次感谢。

Thank you for your reply, Do you know of any good online tutorials that
would show how I would do this?

Thanks again.


我想出了如何创建线程并使用它。但问题是

现在正如你所提到的那样,更新用户界面。


"为了做到这一点,你必须创建一个方法,它将执行你的b $ b $ UI工作。然后你必须创建一个委托,它与你的方法共享

的签名。然后,从您的UI线程,您可以在

控件上调用Invoke方法

,传递委托(指向您的UI更新方法)和

你的

参数。然后该方法将调用传入的委托并且

然后

在UI线程上调用它。


你有任何教程吗?

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?


这篇关于应用程序“冻结”当得到原子进料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆