A
Alexander
I have a dialog that loads a file from a web server, this is done in
an own thread. On finish or failure the thread is supposed to raise an
event notifying the dialog. If the WebRequest now raises a timeout
exception the invoke of the event is done, but the event is never
executed. For testing purposes I exchanged the exception once by a
simple divison by zero which works perfectly, the event is fired and
executed. I debugged the thread to make sure the exception really
reaches the catch block and invokes the event. But I do not understand
why the event function is not called...
I tried the same code on the compact framework on which it is supposed
to run and on the normal framework, but the result is identical.
In the example LoadFileList is the thread function started from
another function of the same class:
Thread loadThread = new Thread(new ThreadStart(LoadFileList));
loadThread.Start();
public void OnLoadFailed(object sender, EventArgs e)
{
this.m_StatusTextBox.Text = "Connection to server failed
!!!\r\nAborting...";
System.Threading.Thread.Sleep(2000);
this.DialogResult = DialogResult.Cancel;
this.Close();
}
public void OnFinished(object sender, EventArgs e)
{
this.m_StatusTextBox.Text = "Success...";
System.Threading.Thread.Sleep(2000);
this.Close();
}
private void LoadFileList()
{
WebRequest objRequest =
System.Net.HttpWebRequest.Create("http://deepthought:7778/WM/files.xml");
objRequest.Timeout = 1000;
try
{
// Timeout exception
WebResponse objResponse = objRequest.GetResponse();
/*
do something with it if success
*/
} catch
{
this.Invoke(new EventHandler(this.OnLoadFailed));
return;
}
this.Invoke(new EventHandler(this.OnFinished));
}
an own thread. On finish or failure the thread is supposed to raise an
event notifying the dialog. If the WebRequest now raises a timeout
exception the invoke of the event is done, but the event is never
executed. For testing purposes I exchanged the exception once by a
simple divison by zero which works perfectly, the event is fired and
executed. I debugged the thread to make sure the exception really
reaches the catch block and invokes the event. But I do not understand
why the event function is not called...
I tried the same code on the compact framework on which it is supposed
to run and on the normal framework, but the result is identical.
In the example LoadFileList is the thread function started from
another function of the same class:
Thread loadThread = new Thread(new ThreadStart(LoadFileList));
loadThread.Start();
public void OnLoadFailed(object sender, EventArgs e)
{
this.m_StatusTextBox.Text = "Connection to server failed
!!!\r\nAborting...";
System.Threading.Thread.Sleep(2000);
this.DialogResult = DialogResult.Cancel;
this.Close();
}
public void OnFinished(object sender, EventArgs e)
{
this.m_StatusTextBox.Text = "Success...";
System.Threading.Thread.Sleep(2000);
this.Close();
}
private void LoadFileList()
{
WebRequest objRequest =
System.Net.HttpWebRequest.Create("http://deepthought:7778/WM/files.xml");
objRequest.Timeout = 1000;
try
{
// Timeout exception
WebResponse objResponse = objRequest.GetResponse();
/*
do something with it if success
*/
} catch
{
this.Invoke(new EventHandler(this.OnLoadFailed));
return;
}
this.Invoke(new EventHandler(this.OnFinished));
}