473,386 Members | 1,835 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,386 software developers and data experts.

Progress bar for my project, multi-threading needed?

Hello experts,
I've been already working on a project and also asked and i've managed
to create a basic Gmail mail sender, but i want to add a progressbar
that shows "sending is in progress" but when i add the
progressbar1.show() when sending then progressbar.hide() after sending
finishes, as known well progressbar is shown after sending is finished
because the main form is in use.

So, must i add multi-threading function to show my progress bar at the
same while my mail is sending simultaneously? Where can i add the code
of that code?

Thanks:

Imports System.Net.mail
Public Class Form1
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Try

Dim message As New MailMessage(txtfrom.Text, txtto.Text,
txtsubject.Text, txtbody.Text)
Dim emailClient As New SmtpClient("smtp.gmail.com")
message.Priority = MailPriority.High
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!")
Catch ex As Exception
MsgBox("Mail couldn't be send" + vbNewLine + "Make sure
you entered correct username/password then try again later",
MsgBoxStyle.Exclamation, "Fail")
End Try

End Sub

End Class

Oct 23 '07 #1
7 2835
it seems like using a progress bar for sending one email is a bit overkill.
usually progress bars are used to show the progress of a long running task.
by the time the progressbar could be re-drawn to show how far it is, the
email would be sent. as for the use of multi-threading, it would be bad
practice (plus it would throw an error in VS2005) to access a control from
another thread. you should only access controls from the main thread. now if
you still want to show a progress bar, youl need to use the forms invoke
method, but as i said, IMHO its a little overkill for sending one email.

hope this helps
--
-iwdu15
Oct 23 '07 #2
Because I am trying to multi-thread an application, I was interested in this
and some other recent posts in this general area and would like to seek some
additional information and clarification.

"iwdu15" <jmmgoalsteratyahoodotcomwrote in message
news:EE**********************************@microsof t.com...
it seems like using a progress bar for sending one email is a bit
overkill.
usually progress bars are used to show the progress of a long running
task.
by the time the progressbar could be re-drawn to show how far it is, the
email would be sent. as for the use of multi-threading, it would be bad
practice (plus it would throw an error in VS2005) to access a control from
another thread. you should only access controls from the main thread. now
if
you still want to show a progress bar, youl need to use the forms invoke
method, but as i said, IMHO its a little overkill for sending one email.

hope this helps
--
-iwdu15
Does "it would be bad practice (...) to access a control from another
thread." mean it would be bad practice (etc) to access a control from a
thread other than the one which created it?

Is it also the case that controls on a form should be, or must be, created
by the same thread which created the form?

Thanks, Bob
Oct 23 '07 #3
On Oct 23, 4:32 am, kimiraikkonen <kimiraikkone...@gmail.comwrote:
Hello experts,
I've been already working on a project and also asked and i've managed
to create a basic Gmail mail sender, but i want to add a progressbar
that shows "sending is in progress" but when i add the
progressbar1.show() when sending then progressbar.hide() after sending
finishes, as known well progressbar is shown after sending is finished
because the main form is in use.

So, must i add multi-threading function to show my progress bar at the
same while my mail is sending simultaneously? Where can i add the code
of that code?

Thanks:

Imports System.Net.mail
Public Class Form1
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Try

Dim message As New MailMessage(txtfrom.Text, txtto.Text,
txtsubject.Text, txtbody.Text)
Dim emailClient As New SmtpClient("smtp.gmail.com")
message.Priority = MailPriority.High

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!")
Catch ex As Exception
MsgBox("Mail couldn't be send" + vbNewLine + "Make sure
you entered correct username/password then try again later",
MsgBoxStyle.Exclamation, "Fail")
End Try

End Sub

End Class
Nothing personal, but haven't we been over this topic multiple times?
It seems you are constantly asking the same type of question over and
over, and Armin, I, and others keep giving you the same answers? I
really hate being rude, and I apologize for the tone of the message,
but it gets rather frustrating answering the same questions from the
same person over and over...

Thanks,

Seth Rowe

Oct 23 '07 #4
Does "it would be bad practice (...) to access a control from another
thread." mean it would be bad practice (etc) to access a control from a
thread other than the one which created it?

Is it also the case that controls on a form should be, or must be, created
by the same thread which created the form?
yes, controls should only be accessed, created, etc from the main thread,
which is the thread that the main form is on. you can have your form update
controls based on info from other threads, which is how progressbars are
usually used. in this case, you need to look at the forms "invoke" method.

hope this helps
--
-iwdu15
Oct 23 '07 #5
"eBob.com" <fa******@totallybogus.comschrieb
Does "it would be bad practice (...) to access a control from
another thread." mean it would be bad practice (etc) to access a
control from a thread other than the one which created it?

Is it also the case that controls on a form should be, or must be,
created by the same thread which created the form?

Yes and yes (must be).
Armin
Oct 23 '07 #6
On Oct 23, 5:22 pm, "Armin Zingler" <az.nos...@freenet.dewrote:
"eBob.com" <faken...@totallybogus.comschrieb
Does "it would be bad practice (...) to access a control from
another thread." mean it would be bad practice (etc) to access a
control from a thread other than the one which created it?
Is it also the case that controls on a form should be, or must be,
created by the same thread which created the form?

Yes and yes (must be).

Armin
OK, but i haven't undestood well something solid, still trying to
learn like multi-threading or working with progress bar simultaneously
with the main form, could you show some example code that shows a
continuous progress bar while sending/connecting is in progress?
Because after i click to send button, the software tries to reach SMTP
server and authenticates, then sends. That procedure usually takes
much time due to slow connections, in that time the form is locked (is
busy, cannot be inteacted) as well.(so that progressbar cannot be
shown without special multi-threading code)

The sample code would be welcomed for running long-length processes in
interaction with progress bar.

Oct 23 '07 #7
>
Nothing personal, but haven't we been over this topic multiple times?
It seems you are constantly asking the same type of question over and
over, and Armin, I, and others keep giving you the same answers? I
really hate being rude, and I apologize for the tone of the message,
but it gets rather frustrating answering the same questions from the
same person over and over...

Thanks,

Seth Rowe
OK, but i haven't undestood well something solid, still trying to
learn like multi-threading or working with progress bar simultaneously
with the main form, could you show some example code that shows a
continuous progress bar while sending/connecting is in progress?
Because after i click to send button, the software tries to reach SMTP
server and authenticates, then sends. That procedure usually takes
much time due to slow connections, in that time the form is locked (is
busy, cannot be inteacted) as well.(so that progressbar cannot be
shown without special multi-threading code)

The sample code would be welcomed for running long-length processes in
interaction with progress bar.

That's why i have asked similiar questions more than one time and if
it will be hard to help/reply for you, it's OK not to get help. But
thanks for the help so far in that group.

Oct 23 '07 #8

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

Similar topics

1
by: Elliott B. | last post by:
We have been asigned a project required by our parent company to have our sales people fill out a form before billing any order to our customers. Our main system runs a Progress db, that's where...
2
by: jayderk | last post by:
Hello All, I would like to have the progress bar look smooth not add the little progress boxes when you change the value? how about a custom image as the progress bar? regards Jay
4
by: aj | last post by:
Alan, you can achieve this by using XMLHttp Async functionality in a javascript file. Create an aspx page in which execute long running SQL query, then do an XMLhttp post to that page from a js...
5
by: A.M | last post by:
Hi, Can I have both C# and VB.NET pages/modules in a visual studio.net project? Thanks, Ali
6
by: Shawn Regan | last post by:
Hello, What is the best practice to show a window/form of some animation while processing is going on in the back ground. I want the user to see something while some processing is taking...
7
by: Pepi Tonas | last post by:
I have a form that takes some time to load because it has to populate some Data. I was trying to display a form on top of it with an activity bar so that user can see that something's going on. ...
6
by: Botak | last post by:
I am able to simulate and run the "thread" as adviced earlier from my previous post. Thanks for the tips. Now I am stucked at how to get the progress status from the thread. I have a main form...
5
by: adh | last post by:
During project loading I display a splash (welcome) form with a progress bar triggered by a timer (on this form). The loading of the project and data, is done Not by this form, but by a hidden Main...
6
by: Vikas Kumar | last post by:
Hi if I want to show a progress bar in my web application how can i do it Like this much % of task has been completed as its shown when installing some desktop application i want to do same in my...
1
by: selvakumari | last post by:
Hi, In my project i need to pop up a form with progressbar while i am populating a treeview from xml file in another form, i used progress.show() function before parsing a xmlfile (progress is...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
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
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...
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...

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.