Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I make the progessbar visible, then check the connection, then make the progressbar hidden. In that Order!

private void button_Click(...)
{
    progBar.Visibility = Visibility.Visible;
    CheckTheConnection();
    progBar.Visibility = Visibility.Hidden;
}
If I remove the Hidden attribute, the CheckConnection runs then the progBar becomes visible. This is the opposite of what I want.
Posted
Updated 19-Jan-11 12:35pm
v2

Put the code in CheckConnection into a thread, and then display/update the progressbar via appropriate mechanisms (Invoke).
 
Share this answer
 
Comments
Nish Nishant 19-Jan-11 19:09pm    
Voted 5, proposed as answer.
hrdfsique 19-Jan-11 19:59pm    
OK, so not as simple as I thought.

Threading seems like it could be a great solution but I am running into a problem that is a bit out of my scope.

I am working on a user control that accepts textBox inputs to create the SQL connection string. The textbox inputs are assigned to Dependancy Properties, whis isn't such a big deal because I could just reassign them in the new thread. Problem is that I can not get the textbox values into the new thread because they are still handled by the main thread.

I'm not sure what to do.
Venkatesh Mookkan 19-Jan-11 21:26pm    
I too propose this as Answer
hrdfsique 21-Jan-11 19:03pm    
Threading is definitely the answer, but after doing much more research... The best method to use in my case is the BackGroundManager Class.
Based on your reply to John, it seems you need to get a basic understanding on how to use threads from WPF. This is a good article on the topic:

http://msdn.microsoft.com/en-us/magazine/cc163328.aspx[^]

Notice how accessing members across the threads is not that complex (although you do need to be careful).
 
Share this answer
 
v3
Comments
Venkatesh Mookkan 19-Jan-11 21:26pm    
Useful share. Thanks Nishant
Espen Harlinn 20-Jan-11 14:00pm    
5+ A solid improvement, the article privides all the required information
Nish Nishant 20-Jan-11 14:05pm    
Thank you, Espen.
hrdfsique 21-Jan-11 19:03pm    
This article did not sufficiently answer my question. After searching "Thread" through the MSDN, the BackgroundManager has the better capability for this particular problem.
Nish Nishant 21-Jan-11 21:31pm    
I don't know what you mean by BackgroundManager. There is a BackgroundWorker class and this class has been well explained in the article I linked to. Anyway glad to hear you've worked it out. Thanks.
 
Share this answer
 
v2

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