puckkk
asked on
Messagebox.showdialog() and multithread
Hello. In my c# app I want to use a Form as a dialog showing progress of time consuming operation. I mean:
I have the mainform, running on the unique main thread. When user click button a long update of data to a remote webservice is launched. I want the following beahvior: user click button, data update runs on the main thread (cause it update main form objects too); while the webservice is running I want that a form dialog is shown to the user (running on a second thread). The form will contain a progressbar update with the progress of the application. When the webservice finished, the second form will close. Here is my code:
//..main Thread:
System.Threading.Thread TR1 = new System.Threading.Thread(u) ;
Italia(); // <-- Webservice taking long time
TR1.Start();
private void u()
{
int y = this.Location.Y;
int nav = ((SisCos)MdiParent).NavTre e.Width;
int parentlocx = this.MdiParent.Location.X;
int parentlocy = this.MdiParent.Location.Y;
Point pnt = new Point(parentlocx + nav + 5, parentlocy + y + 10);
SisCosExplorer.UIsVarie.Me ssBoxSisCo s MB = new SisCosExplorer.UIsVarie.Me ssBoxSisCo s(); // <-- Derived from Form class: it's a form without border
MB.Height = Convert.ToInt16(System.Mat h.Round(th is.Height * .95, 0));
MB.Width = Convert.ToInt16(System.Mat h.Round(th is.Width * .95, 0));
MB.Location = pnt;
MB.ShowDialog();
}
It' s all working great except for one thing: The second form (MB) it's not working like a dialog (even if i call MB.Showdialog). I mean, if the user click on the main form, main form is focused. And I don't want it at all cause the webservice it's uplaoding the main form. I think it's a thread problem. What can I do to make MB working like a real Dialog?
Thanks in advance
I have the mainform, running on the unique main thread. When user click button a long update of data to a remote webservice is launched. I want the following beahvior: user click button, data update runs on the main thread (cause it update main form objects too); while the webservice is running I want that a form dialog is shown to the user (running on a second thread). The form will contain a progressbar update with the progress of the application. When the webservice finished, the second form will close. Here is my code:
//..main Thread:
System.Threading.Thread TR1 = new System.Threading.Thread(u)
Italia(); // <-- Webservice taking long time
TR1.Start();
private void u()
{
int y = this.Location.Y;
int nav = ((SisCos)MdiParent).NavTre
int parentlocx = this.MdiParent.Location.X;
int parentlocy = this.MdiParent.Location.Y;
Point pnt = new Point(parentlocx + nav + 5, parentlocy + y + 10);
SisCosExplorer.UIsVarie.Me
MB.Height = Convert.ToInt16(System.Mat
MB.Width = Convert.ToInt16(System.Mat
MB.Location = pnt;
MB.ShowDialog();
}
It' s all working great except for one thing: The second form (MB) it's not working like a dialog (even if i call MB.Showdialog). I mean, if the user click on the main form, main form is focused. And I don't want it at all cause the webservice it's uplaoding the main form. I think it's a thread problem. What can I do to make MB working like a real Dialog?
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER