c# - How to refresh form while waiting on process - Maybe Threading?
Posted on 2008-11-04
I have a C# app, which tests for connectivity by pinging a server.
When I start the ping processes, I also start a series of 8 cycling graphics that I want to use to show that the application is "processing" and not "hung".
Right before I start the routine for pinging, I start another routine which is used to process the graphics, basically it is a timer control which is set to unhide 1 graphic at a time, in a series of 8, then rehide it, and on the next pass through the timer, the next graphic would unhide, then rehide, etc. (showing motion)
The graphics come up ok, but when the main routine goes to do it's ping, especially noticable on pings that don't reply, the graphic animation doesn't repaint at all until the ping response or failure has come back.
My guess is that I will need to handle the refresh via a second thread, but I don't have a clue how to go about doing that. I've spent the last couple of days trying to read and figure out threading, but am having a tough time of it.
Basically, what I want to be able to do, is:
sequence of events:
1) other code runs from before the ping events
2) a second thread starts, which cycles through the images, and does the refresh's on the main threads form (which would show the animation of the graphics)
3) the ping events would then fire off, and process.
4) after the ping events are ALL done... the second thread (which was used to do the refresh's of the main threads form, would then be terminated. (the second thread terminated, not the main thread)
I am very new to c# but am learning VERY quickly. I'm a "look at working code, and disect it to figure it out" kind of learner, so if someone could help me with how to accomplish this, I would be very appreciative.