473,398 Members | 2,389 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,398 software developers and data experts.

Begininvoke needed?

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!
Jan 5 '08 #1
10 1887
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...
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!
Jan 5 '08 #2
"kimiraikkonen" <ki*************@gmail.comschrieb
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

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.
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.
Please use google to search for "BeginInvoke" in this group. I think it has
been explained many times.
Armin

Jan 5 '08 #3
"Stephany Young" <noone@localhostschrieb
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, a good example how I can learn to make shorter answers. :-)
Armin
Jan 5 '08 #4

"kimiraikkonen" <ki*************@gmail.comkirjoitti viestissä
news:e7**********************************@c23g2000 hsa.googlegroups.com...
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.
BackroundWorker might be the best solution for this. When you press the
button, make the ProgressBar visible and start BackroundWorker which sends
the e-mail message.

-Teemu

Jan 5 '08 #5
On Jan 5, 12:41 pm, "Armin Zingler" <az.nos...@freenet.dewrote:
"kimiraikkonen" <kimiraikkone...@gmail.comschrieb
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

You have to put the task (sending) into another thread if you want to keep
the UI (user interface) busy.
How?
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.
It's just an animation, doesn't calculates anything based on mail
sending (would be great if so)
I have no experience about "invoking types and delagates" and i want
to learn briefly.

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.
Sorry, but i still didn't understand what should i insert into my code
described in my first post to make visible marquee animated progress
bar control while the mail is being sent.
Please use google to search for "BeginInvoke" in this group. I think it has
been explained many times.
I always search but not always gives point solutions, beleive :-)
Armin
I hope to be helped,

Thanks...

Jan 5 '08 #6
On Jan 5, 5:31 pm, "Teemu" <tsir...@hotmail.comwrote:
"kimiraikkonen" <kimiraikkone...@gmail.comkirjoitti viestissänews:e7********************************** @c23g2000hsa.googlegroups.com...
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.

BackroundWorker might be the best solution for this. When you press the
button, make the ProgressBar visible and start BackroundWorker which sends
the e-mail message.

-Teemu
Teemu, how can i use Background Worker? Could you give a sample code
for my first usage?

Thanks.
Jan 5 '08 #7
On Jan 5, 5:31 pm, "Teemu" <tsir...@hotmail.comwrote:
"kimiraikkonen" <kimiraikkone...@gmail.comkirjoitti viestissänews:e7********************************** @c23g2000hsa.googlegroups.com...
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.

BackroundWorker might be the best solution for this. When you press the
button, make the ProgressBar visible and start BackroundWorker which sends
the e-mail message.

-Teemu
Hi, Bgworker is a good idea i tried and worked for showing progress
bar, but i want to hide it when sending process ends by clicking
Messagebox("sent successfully")

I got "crossthread operation not valid....etc". I think i had to
marshal it / use "addressof. " Am i right?

How can i do this (hide progressbar after mail sending finishes)?

Thanks.
Jan 5 '08 #8
OK, don't mind. I found solution for hiding progress bar by putting
"progressbar1.hide" inside background worker's "RunWorkerCompleted"
event.
Jan 5 '08 #9
Armin,
Thx Stephany, a good example how I can learn to make shorter answers. :-)
No please keep your own style, at least I like it.

:-)

Cor
Jan 6 '08 #10
"Cor Ligthert[MVP]" <no************@planet.nlschrieb
Armin,
Thx Stephany, a good example how I can learn to make shorter
answers. :-)
No please keep your own style, at least I like it.

:-)
Thx.

*blush*

:)
Armin
Jan 6 '08 #11

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

Similar topics

5
by: Marina | last post by:
Hi, we have an app, that executes jobs submitted from an outside application. It executes them asynchronusly, by creating a delegate to the method that can run the job, and calling BeginInvoke on...
6
by: arkam | last post by:
Hi, I found a sample on internet : formMain.BeginInvoke(new MyClickHandler(this.OnMyClick)); I would like to do the same but in a class library where there is no forms ! Where can I find...
9
by: David Sworder | last post by:
Hi, I have a form that displays data (is that vague enough for you?). The data comes in on a thread-pool thread. Since the thread pool thread is not the same as the UI thread, the callback...
6
by: Valerie Hough | last post by:
I'm not entirely sure what the difference is between these two approaches. In order to avoid reentrant code, I was using Control.BeginInvoke in my UI to cause an asynchronous activity to be done...
9
by: john doe | last post by:
I have a question about BeginInvoke method found on the Control class. To quote the docs: "Executes the specified delegate asynchronously with the specified arguments, on the thread that the...
3
by: RWF | last post by:
I have a windows form of which I will be saving the user's selections from DropDownBoxes, CheckBoxes, and RadioButtons. Once the choices are collected, I really will have no use for any of the...
2
by: Flack | last post by:
Hello, If I understand BeginInvoke correctly, when it is called your delegate is run on a thread pool thread. Now, if you supplied a callback delegate, that too is called on the same thread...
2
by: =?Utf-8?B?a2VubmV0aG1Abm9zcGFtLm5vc3BhbQ==?= | last post by:
vs2005, c# Trying to understand why one way works but the other doesnt. I have not tried to create a simpler mdi/child/showdialog app for posting purposes (I think even this would not be so small...
7
by: Ben Voigt [C++ MVP] | last post by:
As much as the CLR team assures us that it's ok to fire-and-forget Control.BeginInvoke, it seems it isn't. Maybe this is a bug. See for example: the comments in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.