Click here to Skip to main content
15,919,879 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all, I have created small windows apllication, in my form user will enter some data in the TextBox and user will save the data, but in background there should some process go on like checking the database connection whether it's open or not,

Both action should go on. Entering data as well as connectivity process
How to do this.
Posted
Updated 26-Mar-12 23:22pm
v2

You can make your application mutithreaded, see, for instance, the CodeProject's article "Introduction to making multithreaded VB.NET Apps"[^].
 
Share this answer
 
Comments
Shahin Khorshidnia 27-Mar-12 5:24am    
+5
Sergey Alexandrovich Kryukov 27-Mar-12 19:24pm    
This is informative, my 5, but, strictly speaking, there is no "at the same time". This is not real time. I hope you'll like my answer... :-)
--SA
CPallini 29-Mar-12 3:34am    
Well that's the 'UI level' same time. :-)
Sergey Alexandrovich Kryukov 29-Mar-12 12:40pm    
I would understand it. There were a couple of cases where OP asked how to call "two methods at the same time", but in fact they just wanted to call two methods from one no matter in what order; some people do not understand what the call is...
--SA
Look at using a BackgroundWorker Thread: MSDN[^] - it is probably the simplest way to get started with threading. The link includes an example.
 
Share this answer
 
Comments
Shahin Khorshidnia 27-Mar-12 5:24am    
+5
Nothing can be guaranteed to happen at the same time, at least not in the non-real-time system.
If you do something in one thread, your actions follow consecutively. If you do it in different threads, they may overlap in time, but as thread scheduling is probabilistic, nothing can give you 100% guarantee exact timing. And if some objects move fast enough, the concept of the "same time" for a space-like interval does not even makes sense :-), please see:
http://en.wikipedia.org/wiki/Space-like#Space-like_interval[^].

—SA
 
Share this answer
 
Comments
Shahin Khorshidnia 27-Mar-12 19:09pm    
Good Point
Sergey Alexandrovich Kryukov 27-Mar-12 19:24pm    
Thank you, Shahin.
--SA
CPallini 29-Mar-12 3:33am    
My 5.
Sergey Alexandrovich Kryukov 29-Mar-12 10:44am    
Thank you.
--SA
You should use a background worker on your application..
the one that will check the
VB
friend withevents Bw1 as new backgroundworker

VB
Private Sub StartButton_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) _
                              Handles StartButton.Click
        Bw1.RunWorkerAsync()
    End Sub


''here is the event for the backgroundworker
''check for the connection

    Private Sub Bw1_DoWork(ByVal sender As System.Object, _
   ByVal e As System.ComponentModel.DoWorkEventArgs)Handles Bw1.DoWork
''code here
    End Sub


You can also use system threading
 
Share this answer
 
v2
Comments
Shahin Khorshidnia 27-Mar-12 5:23am    
2 because nothing more than Solution1 and Solution2.
sameertm 27-Mar-12 5:24am    
can u give me some sample code for threading.
Shahin Khorshidnia 27-Mar-12 5:26am    
Refer to the links in Solution1, there is a nice standard sample for BackgroundWorker. and a good sample in the article that linked in solution 2 for mutithread
sameertm 27-Mar-12 5:30am    
i created one thread when my form is load thread will start.after thread start there will be some process go's on once ,once the prcoess is over,again i need to start my thread. this is my sample code

Private Sub Startup_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

t = New Thread(AddressOf Me.BackgroundProcess)
t.Start()
End Sub
Private Sub BackgroundProcess()
''my process
''
''
End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900