You are waiting in the main windows events thread, so your GUI will be frozen Try this (using non static methods allows you to use the Control. Invoke method to run callbacks on the windows GUI thread and free this thread in order to redraw) public partial class Form1 : Form { private static WebClient client = new WebClient(); private static ManualResetEvent uploadLock = new ManualResetEvent(false); private void Upload() { try { Cursor=Cursors. Wait; Uri uri = new Uri("http://localhost/Default2.
Aspx"); String filename = @"C:\Test\1. Dat"; client.Headers. Add("UserAgent", "TestAgent"); client.
UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressCallback); client. UploadFileCompleted += new UploadFileCompletedEventHandler(UploadFileCompleteCallback); client. UploadFileAsync(uri, "POST", filename); } catch (Exception e) { Console.
WriteLine(e.StackTrace.ToString()); this. Cursor=Cursors. Default; this.
Enabled=false; } } public void UploadFileCompleteCallback(object sender, UploadFileCompletedEventArgs e) { // this callback will be invoked by the async upload handler on a ThreadPool thread, so we cannot touch anything GUI-related. For this we have to switch to the GUI thread using control. BeginInvoke if(this.
InvokeRequired) { // so this is called in the main GUI thread this. BeginInvoke(new UploadFileCompletedEventHandler(UploadFileCompleteCallback); // beginInvoke frees up the threadpool thread faster. Invoke would wait for completion of the callback before returning.
} else { Cursor=Cursors. Default; this. Enabled=true; MessageBox.
Show(this,"Upload done","Done"); } public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Upload(); } } } And do the same thing in your progress (you could update a progressbar indicator for example) Cheers, Florian.
You are waiting in the main windows events thread, so your GUI will be frozen. Try this (using non static methods allows you to use the Control. Invoke method to run callbacks on the windows GUI thread and free this thread in order to redraw) public partial class Form1 : Form { private static WebClient client = new WebClient(); private static ManualResetEvent uploadLock = new ManualResetEvent(false); private void Upload() { try { Cursor=Cursors.
Wait; Uri uri = new Uri("http://localhost/Default2. Aspx"); String filename = @"C:\Test\1. Dat"; client.Headers.
Add("UserAgent", "TestAgent"); client. UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressCallback); client. UploadFileCompleted += new UploadFileCompletedEventHandler(UploadFileCompleteCallback); client.
UploadFileAsync(uri, "POST", filename); } catch (Exception e) { Console. WriteLine(e.StackTrace.ToString()); this. Cursor=Cursors.
Default; this. Enabled=false; } } public void UploadFileCompleteCallback(object sender, UploadFileCompletedEventArgs e) { // this callback will be invoked by the async upload handler on a ThreadPool thread, so we cannot touch anything GUI-related. For this we have to switch to the GUI thread using control.
BeginInvoke if(this. InvokeRequired) { // so this is called in the main GUI thread this. BeginInvoke(new UploadFileCompletedEventHandler(UploadFileCompleteCallback); // beginInvoke frees up the threadpool thread faster.
Invoke would wait for completion of the callback before returning. } else { Cursor=Cursors. Default; this.
Enabled=true; MessageBox. Show(this,"Upload done","Done"); } public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Upload(); } } } And do the same thing in your progress (you could update a progressbar indicator for example). Cheers, Florian.
– George2 Oct 9 '09 at 12:36 1 The Windows GUI are message-driven, although WinForms hides this from you. Each Windows app uses a 'Message Pumping' thread that will deliver messages to the GUI widgets (such as mouse moved, user click, key pressed, and much more0. Your handlers run in the main windows message thread, thus if you are waiting on an event, you will block the windows message pump and the gui will appear 'frozen'.
You usually can tell when it can't redraw itself for example. See here for a great resource: msdn.microsoft. Com/en-us/library/3s8xdz5c%28VS.80%29.
Aspx – Florian Doyon Oct 9 '09 at 14:00 Where do you invoke Upload method? – George2 Oct 9 '09 at 14:34 1 Exactly as you did put it, in the click handler. I'll update the code above.
– Florian Doyon Oct 9 '09 at 14:43 1 Bear with me :) This callback (UploadFileCompleteCallback) will be invoked on a thread that belongs to the ThreadPool. Because the way Winforms works under the hood, you can only access winforms controls from the winforms thread. As the callback is called in the threadpool the 1st time, we detect that if we want to talk to winforms we need to switch threads(InvokeRequired), then if it is, we actually do the switch(BeginInvoke) and call ourselves.
So the 2nd time this callback is executed, it's in the winforms thread, and InvokeRequired returns false, so we can actually do GUI stuff. – Florian Doyon Oct 9 '09 at 16:53.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.