Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I I just want to Display a another form while i Updating records to DB lets say it will take a while and during that time i want to load a new form and say its updating DB or something. i did nt use back ground worker.i actually want to display pop up Message with gif and just close from when updation complete. its working but when it did nt show loaded forms lables and images clearly.i cannot drag them its like stuck
C#
frmloading loading = new frmloading();
loading.StartPosition = FormStartPosition.CenterScreen;
loading.Show();
try
{
    //My coding....   
}
loading.Close();
MessageBox.Show("Sucessfully Updated!!!");
dataGridView1.DataSource = "";
Posted
Updated 13-Dec-15 20:49pm
v5
Comments
BillWoodruff 14-Dec-15 4:09am    
If this is Windows Forms, and you are using 'Form.Show, not Form.ShowModal, I don't see why there should be any blocking of actions that affect the visual state of your Controls in another Form.

Please say more about what "when it did nt show loaded forms lables and images clearly" means in more detail. What do you see ? What don't you see ?

1 solution

Quote:
i did nt use back ground worker
That's the problem. In order Keep the GUI responsive you need to do the long-time-taking operation in another thread.

[update]
If you have 'crss-threading' issues then MSDN is waiting for you (have a good read): "How to: Make Thread-Safe Calls to Windows Forms Controls"[^].
[/update]
 
Share this answer
 
v2
Comments
Hesha 14-Dec-15 3:10am    
hi i did like that but im getting following error

?ex
{"Cross-thread operation not valid: Control 'dataGridView1' accessed from a thread other than the thread it was created on."}
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233079
HelpLink: null
InnerException: null
Message: "Cross-thread operation not valid: Control 'dataGridView1' accessed from a thread other than the thread it was created on."
Source: "System.Windows.Forms"
StackTrace: " at System.Windows.Forms.Control.get_Handle()\r\n at System.Windows.Forms.DataGridView.FlushDisplayedChanged()\r\n at System.Windows.Forms.DataGridView.PerformLayoutPrivate(Boolean useRowShortcut, Boolean computeVisibleRows, Boolean invalidInAdjustFillingColumns, Boolean repositionEditingControl)\r\n at System.Windows.Forms.DataGridView.ResetUIState(Boolean useRowShortcut, Boolean computeVisibleRows)\r\n at System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PreNotification(CollectionChangeAction cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow& dataGridViewRow, Boolean changeIsInsertion)\r\n at System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs e, Int32 rowIndex, Int32 rowCount, Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)\r\n at System.Windows.Forms.DataGridViewRowCollection.ClearInternal(Boolean recreateNewRow)\r\n at System.Windows.Forms.DataGridView.RefreshCol
umnsAndRows()\r\n at System.Windows.Forms.DataGridView.OnDataSourceChanged(EventArgs e)\r\n at System.Windows.Forms.DataGridView.set_DataSource(Object value)\r\n at Exp_GFM.frmVarifyInvoices.submitdata1() in C:\\Users\\Heshan\\Documents\\Visual Studio 2015\\Projects\\Exp_GFM\\Exp_GFM\\frmVarifyInvoices.cs:line 436"
TargetSite: {IntPtr get_Handle()}

here was the code i tried

private void submitdata()
{


List<task> tasks = new List<task>();
tasks.Add(Task.Run(() => { loading(); }));
tasks.Add(Task.Run(() => { submitdata1(); }));
Task.WaitAll(tasks.ToArray());


}
CPallini 14-Dec-15 5:36am    
See my updated solution.
Guti7 14-Dec-15 8:49am    
I guess you need to switch back to UI thread to update UI.

Please check following article-
http://stackoverflow.com/questions/16668207/update-the-gui-from-another-thread-in-c-sharp-change-back-to-the-main-thread-o

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