Click here to Skip to main content
15,905,785 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
actually i have 120 records in database when i run my application some time it will hang my application so i need to run that method at background of my application.


please please help me....
Posted
Updated 27-Nov-13 20:33pm
v2
Comments
Sergey Alexandrovich Kryukov 28-Nov-13 2:32am    
Help with what? You say nothing except some false statement. If you don't understand how to use some class properly, it does not mean it does not work. Look: no information, no help.
—SA
hareshdgr8 28-Nov-13 2:36am    
i will sent you code please check it

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
BGW.WorkerReportsProgress = True
BGW.WorkerSupportsCancellation = True
BGW.RunWorkerAsync()
End Sub

Private Sub BGW_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BGW.DoWork
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
getDatafromLoad()

System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = True

End Sub

Private Sub BGW_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BGW.RunWorkerCompleted
If e.Cancelled = True Then
'lblPercent.Text = "Operation Cancelled"
MsgBox("Operation Canceled")
'WorkEventRunning = False
ElseIf e.Error IsNot Nothing Then
'lblPercent.Text = "Failed" 'e.Error.Message.ToString
Else
MsgBox("Done")

End If
End Sub

You cannot call any instance methods or properties of currently executing UI from any thread other then UI thread. If you need to update UI from such non-UI thread, you need to use UI thread invocation mechanism. Please see my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

And I would advise to never disable the check for illegal cross-thread calls. This is unsafe practice. You don't have any serious reason to use it.

—SA
 
Share this answer
 
Comments
Maciej Los 28-Nov-13 4:11am    
Holy words!
Sergey Alexandrovich Kryukov 28-Nov-13 4:40am    
Thank you, Maciej.
—SA
http://www.dreamincode.net/forums/topic/88605-the-background-worker/[^]

BackgroundWorker Class Sample for Beginners[^]

maybee check thoose links..
but next time you could google them yourself ^^
 
Share this answer
 

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