multithreading - How to display a "please wait" message box while the processing goes on in C#? -


i have windows application in using web reference show current sms balance in account of particular user.here code using:

thread t1 = new thread(new threadstart(showwaitmessage));             t1.start();             xmlnode xmlnde = ws.bsacbalance(txtloginid.text, txtpassword.text);             string sresponse = xmlnde.childnodes[0].innerxml;             if (sresponse.contains("authentication failed"))             {                 t1.abort();                 messagebox.show("invalid login id or password !", "information", messageboxbuttons.ok, messageboxicon.asterisk);                                 }             else             {                 t1.abort();                 messagebox.show("total balance in account rs : " + sresponse , "information", messageboxbuttons.ok, messageboxicon.asterisk);             }  public void showwaitmessage()     {                      messagebox.show("please wait ......");     } 

the ws.bsacbalance method connects application web, takes 2 3 seconds execute. in meanwhile, want display "please wait" message trying use threading , displaying message through message box.now once desired operation completed, want "please wait" message box hide, doesn't happen.what should ?

messagebox designed take user's input. not present "native" means close programmatically. have 2 options:

option 1.

a) define new class waitform, derived system.windows.forms.form;

b) define public method closeme in waitform execute form.close() once being called outside.

c) create instance of waitform when need display wait message , call inherited method showdialog().

d) once operation completed, call closeme thread.

option 2:(force messagebox closing)

use windows api function findwindow, not native .net. have include:

[dllimport("user32.dll", entrypoint = "findwindow", setlasterror = true)] static extern intptr findwindowbycaption(intptr zeroonly, string lpwindowname); 
  • and then, once operation done, call

intptr hwnd = findwindowbycaption(intptr.zero, <yourwaitmessageboxtitle>); if (hwnd.toint32() != 0) postmessage(hwnd, wm_close, 0, 0);


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -