Begininvoke需要吗? [英] Begininvoke needed?

查看:71
本文介绍了Begininvoke需要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个小应用程序,使用.NET的SmtpClient类发送并发送

。但问题是我放置了一个选框类型的进度条

有一个动画并默认隐藏。


然后我放置了progressbar1.show ;代码内部发送按钮,但

问题是在发送邮件后/

操作结束后显示进度条。我希望我的表单同时显示进度条

发送邮件。


并且在发送过程中表单似乎被绞死并锁定但仍然是

操作在一段时间后成功结束。我已经在没有帮助的情况下搜索了

类似的线程,我想我需要在我的代码中插入一种

调用/委托部分以允许我的表单进行交互

运营期间。我的代码:


Private Sub btnSubmit_Click(ByVal sender As Object,ByVal e As

System.EventArgs)处理_btnSubmit.Click

ProgressBar1.Show()

Dim message As New MailMessage(txtfrom.Text,txtto.Text,

txtsubject.Text,txtbody.Text)

Dim emailClient As New SmtpClient(" smtp.gmail.com")

Dim SMTPUserInfo As New

System.Net.NetworkCredential(txtSMTPUser.Text +

_" @ gmail.com",txtSMTPPass.Text)

emailClient.UseDefaultCredentials = False

emailClient.Credentials = SMTPUserInfo

emailClient.Port = 587

emailClient.EnableSsl = True

emailClient.Send(消息)

MsgBox(邮件已成功发送 ;,MsgBoxStyle.Information,

成功!


结束子

我没有经验调用类型和分解我想简单地学习




如果你帮忙解释一下代码我会很高兴。

谢谢!

Hi,
I have a small app which sends using .NET''s SmtpClient Class and sends
well. But the problem is that i placed a marquee-type progress bar to
have an animation and hide by default.

Then i placed "progressbar1.show" code inside send button, but the
problem is that progress bar is shown after the mail is sent / after
operation ends. I want my form displays progress bar at the same time
with mail is being sent.

And during sending process form seems hanged and locked but still
operation is ended successfully after a while. I have searched for
similiar threads with no help and i think i need to insert a kind of
invoking / delegation part into my code to allow my form tointeract
during operation. My code:

Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles _btnSubmit.Click
ProgressBar1.Show()
Dim message As New MailMessage(txtfrom.Text, txtto.Text,
txtsubject.Text, txtbody.Text)
Dim emailClient As New SmtpClient("smtp.gmail.com")
Dim SMTPUserInfo As New
System.Net.NetworkCredential(txtSMTPUser.Text +
_ "@gmail.com", txtSMTPPass.Text)
emailClient.UseDefaultCredentials = False
emailClient.Credentials = SMTPUserInfo
emailClient.Port = 587
emailClient.EnableSsl = True
emailClient.Send(message)
MsgBox("Mail was sent successfully", MsgBoxStyle.Information,
"Success!")

End Sub
I have no experience about "invoking types and delagates" and i want
to learn briefly.

If you help and explain about the code i''d be so glad.

Thanks!

推荐答案

这与''调用''和/或''委托'无关。


只是你的UI线程被阻止,你点击提交按钮,直到你取消MessageBox对话框为止。

" kimiraikkonen" < ki ************* @ gmail.comwrote in message

news:e7 ***************** ***************** @ c23g2000 hsa.googlegroups.com ...
It''s nothing to do with ''invoking'' and/or ''delegates''.

It is simply that your UI thread is being blocked from the point where you
click the ''submit'' button until you have dismissed the MessageBox dialog.
"kimiraikkonen" <ki*************@gmail.comwrote in message
news:e7**********************************@c23g2000 hsa.googlegroups.com...



我有一个小应用程序,使用.NET的SmtpClient类发送并发送

。但问题是我放置了一个选框类型的进度条

有一个动画并默认隐藏。


然后我放置了progressbar1.show ;代码内部发送按钮,但

问题是在发送邮件后/

操作结束后显示进度条。我希望我的表单同时显示进度条

发送邮件。


并且在发送过程中表单似乎被绞死并锁定但仍然是

操作在一段时间后成功结束。我已经在没有帮助的情况下搜索了

类似的线程,我想我需要在我的代码中插入一种

调用/委托部分以允许我的表单进行交互

运营期间。我的代码:


Private Sub btnSubmit_Click(ByVal sender As Object,ByVal e As

System.EventArgs)处理_btnSubmit.Click

ProgressBar1.Show()

Dim message As New MailMessage(txtfrom.Text,txtto.Text,

txtsubject.Text,txtbody.Text)

Dim emailClient As New SmtpClient(" smtp.gmail.com")

Dim SMTPUserInfo As New

System.Net.NetworkCredential(txtSMTPUser.Text +

_" @ gmail.com",txtSMTPPass.Text)

emailClient.UseDefaultCredentials = False

emailClient.Credentials = SMTPUserInfo

emailClient.Port = 587

emailClient.EnableSsl = True

emailClient.Send(消息)

MsgBox(邮件已成功发送 ;,MsgBoxStyle.Information,

成功!


结束子


我没有关于调用类型的经验nd delagates我想简单地学习




如果你帮忙解释一下代码我会很高兴。

谢谢!
Hi,
I have a small app which sends using .NET''s SmtpClient Class and sends
well. But the problem is that i placed a marquee-type progress bar to
have an animation and hide by default.

Then i placed "progressbar1.show" code inside send button, but the
problem is that progress bar is shown after the mail is sent / after
operation ends. I want my form displays progress bar at the same time
with mail is being sent.

And during sending process form seems hanged and locked but still
operation is ended successfully after a while. I have searched for
similiar threads with no help and i think i need to insert a kind of
invoking / delegation part into my code to allow my form tointeract
during operation. My code:

Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles _btnSubmit.Click
ProgressBar1.Show()
Dim message As New MailMessage(txtfrom.Text, txtto.Text,
txtsubject.Text, txtbody.Text)
Dim emailClient As New SmtpClient("smtp.gmail.com")
Dim SMTPUserInfo As New
System.Net.NetworkCredential(txtSMTPUser.Text +
_ "@gmail.com", txtSMTPPass.Text)
emailClient.UseDefaultCredentials = False
emailClient.Credentials = SMTPUserInfo
emailClient.Port = 587
emailClient.EnableSsl = True
emailClient.Send(message)
MsgBox("Mail was sent successfully", MsgBoxStyle.Information,
"Success!")

End Sub
I have no experience about "invoking types and delagates" and i want
to learn briefly.

If you help and explain about the code i''d be so glad.

Thanks!


" kimiraikkonen" < ki ************* @ gmail.comschrieb
"kimiraikkonen" <ki*************@gmail.comschrieb



我有一个小使用.NET的SmtpClient类发送的应用程序和

发送良好。但问题是我放置了一个字幕式进度

栏来制作动画并默认隐藏。


然后我放置了progressbar1.show ;代码内部发送按钮,但

问题是在发送邮件后/

操作结束后显示进度条。我希望我的表单显示进度条同时

时间正在发送邮件。


并且在发送过程中表单似乎被挂起并锁定但仍然是

操作在一段时间后成功结束。我已经在没有帮助的情况下搜索了

类似的线程,我想我需要在我的代码中插入一种

调用/委托部分以允许我的表单进行交互

运营期间。我的代码:


Private Sub btnSubmit_Click(ByVal sender As Object,ByVal e As

System.EventArgs)处理_btnSubmit.Click

ProgressBar1.Show()

Dim message As New MailMessage(txtfrom.Text,txtto.Text,

txtsubject.Text,txtbody.Text)

Dim emailClient As New SmtpClient(" smtp.gmail.com")

Dim SMTPUserInfo As New

System.Net.NetworkCredential(txtSMTPUser.Text +

_" @ gmail.com",txtSMTPPass.Text)

emailClient.UseDefaultCredentials = False

emailClient.Credentials = SMTPUserInfo

emailClient.Port = 587

emailClient.EnableSsl = True

emailClient.Send(消息)

MsgBox(邮件已成功发送 ;,MsgBoxStyle.Information,

成功!


结束次级
Hi,
I have a small app which sends using .NET''s SmtpClient Class and
sends well. But the problem is that i placed a marquee-type progress
bar to have an animation and hide by default.

Then i placed "progressbar1.show" code inside send button, but the
problem is that progress bar is shown after the mail is sent / after
operation ends. I want my form displays progress bar at the same
time with mail is being sent.

And during sending process form seems hanged and locked but still
operation is ended successfully after a while. I have searched for
similiar threads with no help and i think i need to insert a kind of
invoking / delegation part into my code to allow my form tointeract
during operation. My code:

Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles _btnSubmit.Click
ProgressBar1.Show()
Dim message As New MailMessage(txtfrom.Text, txtto.Text,
txtsubject.Text, txtbody.Text)
Dim emailClient As New SmtpClient("smtp.gmail.com")
Dim SMTPUserInfo As New
System.Net.NetworkCredential(txtSMTPUser.Text +
_ "@gmail.com", txtSMTPPass.Text)
emailClient.UseDefaultCredentials = False
emailClient.Credentials = SMTPUserInfo
emailClient.Port = 587
emailClient.EnableSsl = True
emailClient.Send(message)
MsgBox("Mail was sent successfully", MsgBoxStyle.Information,
"Success!")

End Sub



你必须把任务(发送)如果你想保持UI(用户界面)忙碌,请进入另一个线程。


ProgressBar1是否真的反映了发送的进度?或者它只是动画?
动画?如果你必须反映进度,你必须从工作线程调用

ProgressBar1的BeginInvoke方法。


You have to put the task (sending) into another thread if you want to keep
the UI (user interface) busy.

Does the ProgressBar1 really reflect the progress of sending? Or is it just
an animation? If you had to reflect the progress, you would have to call
ProgressBar1''s BeginInvoke method from the working thread.


我没有关于调用类型和分解的经验我想简单地学习


I have no experience about "invoking types and delagates" and i want
to learn briefly.



委托是一个对象,包含对某个

方法/程序的引用。您可以传递一个委托,获得

委托的人可以调用委托中引用的方法。


BeginInvoke使传递方法(包含在委托中)在

UI线程中执行。然后UI线程可以更新进度条,这不是工作线程允许的b $ b。


BeginInvoke是(比如)向UI发送消息线。消息说:

执行此方法。 UI线程将收到消息并且像

指示一样(一旦空闲)。

A delegate is an object containing a reference to a certain
method/procedure. You can pass a delegate around, and the one who gets the
delegate is able to call the method that is referenced in the delegate.

BeginInvoke makes the passed method (wrapped in a delegate) execute in the
UI thread. The UI thread then can update the progress bar, which is not
allowed from the worker thread.

BeginInvoke is (like) sending a message to the UI thread. The message says:
"execute this method". The UI thread will receive the message and do like
instructed (as soon as it is idle).


如果你帮助和解释代码我会很高兴。
If you help and explain about the code i''d be so glad.



请使用google搜索BeginInvoke在这个组中。我认为已经多次解释了



Armin

Please use google to search for "BeginInvoke" in this group. I think it has
been explained many times.
Armin


" Stephany Young" < noone @ localhostschrieb
"Stephany Young" <noone@localhostschrieb

这与''调用''和/或''委托'无关。

只是你的UI线程被阻止了点

,你点击提交按钮,直到你解雇了

MessageBox对话。
It''s nothing to do with ''invoking'' and/or ''delegates''.

It is simply that your UI thread is being blocked from the point
where you click the ''submit'' button until you have dismissed the
MessageBox dialog.



Thx Stephany,一个很好的例子,我可以学习如何缩短答案。 :-)

Armin

Thx Stephany, a good example how I can learn to make shorter answers. :-)
Armin


这篇关于Begininvoke需要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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