Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello All

I want to show a form with a progress bar for display server processing in windows app.If i open 5 win forms i have to display this progress bar window for the top most where ever.
How can i do this?Can any one tell me how to use handle to the window (hwnd) to this problem.Waiting for your reply.

Regards
Shameen
Posted
Comments
Sergey Alexandrovich Kryukov 17-Nov-11 2:17am    
Why HWND?
--SA

1 solution

You never need HWND to do this. Remember, using HWND will immediately make your Forms application non-portable. If you write a Forms application accurately, it will run on many platforms without recompilation (under Mono). A single use of HWND will spoil it.

Most importantly, you don't need it.

Instead, you need to create a separate thread and notify UI on progress using a progress bar. Here is how:

You cannot call anything related to UI from non-UI thread. Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA
 
Share this answer
 
v2
Comments
Nish Nishant 17-Nov-11 10:37am    
Good answer. My 5!
Sergey Alexandrovich Kryukov 17-Nov-11 11:41am    
Thank you, Nishant.
--SA

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