473,799 Members | 3,866 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.s how" 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.EventArg s) Handles _btnSubmit.Clic k
ProgressBar1.Sh ow()
Dim message As New MailMessage(txt from.Text, txtto.Text,
txtsubject.Text , txtbody.Text)
Dim emailClient As New SmtpClient("smt p.gmail.com")
Dim SMTPUserInfo As New
System.Net.Netw orkCredential(t xtSMTPUser.Text +
_ "@gmail.com ", txtSMTPPass.Tex t)
emailClient.Use DefaultCredenti als = False
emailClient.Cre dentials = SMTPUserInfo
emailClient.Por t = 587
emailClient.Ena bleSsl = True
emailClient.Sen d(message)
MsgBox("Mail was sent successfully", MsgBoxStyle.Inf ormation,
"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 1912
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.
"kimiraikko nen" <ki************ *@gmail.comwrot e in message
news:e7******** *************** ***********@c23 g2000hsa.google groups.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.s how" 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.EventArg s) Handles _btnSubmit.Clic k
ProgressBar1.Sh ow()
Dim message As New MailMessage(txt from.Text, txtto.Text,
txtsubject.Text , txtbody.Text)
Dim emailClient As New SmtpClient("smt p.gmail.com")
Dim SMTPUserInfo As New
System.Net.Netw orkCredential(t xtSMTPUser.Text +
_ "@gmail.com ", txtSMTPPass.Tex t)
emailClient.Use DefaultCredenti als = False
emailClient.Cre dentials = SMTPUserInfo
emailClient.Por t = 587
emailClient.Ena bleSsl = True
emailClient.Sen d(message)
MsgBox("Mail was sent successfully", MsgBoxStyle.Inf ormation,
"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
"kimiraikko nen" <ki************ *@gmail.comschr ieb
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.s how" 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.EventArg s) Handles _btnSubmit.Clic k
ProgressBar1.Sh ow()
Dim message As New MailMessage(txt from.Text, txtto.Text,
txtsubject.Text , txtbody.Text)
Dim emailClient As New SmtpClient("smt p.gmail.com")
Dim SMTPUserInfo As New
System.Net.Netw orkCredential(t xtSMTPUser.Text +
_ "@gmail.com ", txtSMTPPass.Tex t)
emailClient.Use DefaultCredenti als = False
emailClient.Cre dentials = SMTPUserInfo
emailClient.Por t = 587
emailClient.Ena bleSsl = True
emailClient.Sen d(message)
MsgBox("Mail was sent successfully", MsgBoxStyle.Inf ormation,
"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 "BeginInvok e" in this group. I think it has
been explained many times.
Armin

Jan 5 '08 #3
"Stephany Young" <noone@localhos tschrieb
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

"kimiraikko nen" <ki************ *@gmail.comkirj oitti viestissä
news:e7******** *************** ***********@c23 g2000hsa.google groups.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.s how" 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...@free net.dewrote:
"kimiraikko nen" <kimiraikkone.. .@gmail.comschr ieb
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.s how" 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.EventArg s) Handles _btnSubmit.Clic k
ProgressBar1.Sh ow()
Dim message As New MailMessage(txt from.Text, txtto.Text,
txtsubject.Text , txtbody.Text)
Dim emailClient As New SmtpClient("smt p.gmail.com")
Dim SMTPUserInfo As New
System.Net.Netw orkCredential(t xtSMTPUser.Text +
_ "@gmail.com ", txtSMTPPass.Tex t)
emailClient.Use DefaultCredenti als = False
emailClient.Cre dentials = SMTPUserInfo
emailClient.Por t = 587
emailClient.Ena bleSsl = True
emailClient.Sen d(message)
MsgBox("Mail was sent successfully", MsgBoxStyle.Inf ormation,
"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 "BeginInvok e" 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...@hotmai l.comwrote:
"kimiraikko nen" <kimiraikkone.. .@gmail.comkirj oitti viestissänews:e 7************** *************** *****@c23g2000h sa.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.s how" 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...@hotmai l.comwrote:
"kimiraikko nen" <kimiraikkone.. .@gmail.comkirj oitti viestissänews:e 7************** *************** *****@c23g2000h sa.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.s how" 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("sen t successfully")

I got "crossthrea d 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.h ide" inside background worker's "RunWorkerCompl eted"
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

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

Similar topics

5
368
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 the method. Throughout the job itself, we use the CallContext class to store information that is needed by many classes in the call stream. This works well, and concurrent threads are working fine. What happens is, that after a job is done,...
6
5590
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 a BeginInvoke equivalent for a class library ?
9
7604
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 function of my form follows the standard design pattern: if(IsDisposed){ return; }
6
15161
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 on the UI's message loop. I began to get System.ExecutionEngineException errors so (on the theory of do something different if what you're doing isn't working) I switched to using delegate.BeginInvoke with the appropriate EndInvoke and the problem...
9
5671
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 control's underlying handle was created on." Which is fine, but I'm wondering how does this method get called asynchronously if it's on the same thread we are working on? Surely it blocks the thread until returned?
3
6054
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 controls. Is there a benefit of using Control.BeginInvoke opposed to ThreadPool.QueueWorkItem? From the threads I have briefly scanned over on the www, there really is no difference other. Some have mentioned that ThreadPool.QueueWorkItem maybe...
2
3815
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 pool thread. My question is this: Do I ever need to check the value of InvokeRequired in my callback method before working with some GUI controls? Won't it always be required since the callback is running on a thread pool thread? I see some code...
2
4427
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 or simple). I am hoping the description will generate some ideas I can check out. PROBLEM: ----------------- Switching to UI thread using Invoke(), everything seems good.
7
5677
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 http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx I was encountering a bug that disappeared when debugging. Not when a debugger is attached, mind you, but when I placed a breakpoint near the code. Adding Trace.WriteLine statements showed that the failing code was...
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9543
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10237
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7567
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.