S
Steve
I need to update my UI from a Process or worker thread. I did some readinf
and basically ended up adapting an MS example to fot my needs. It all made
sense until I tried it
My process makes calls to a Singleton logger class which in turn makes calls
to a delegate to add items to a listbox in my WinForm.
Here is the code that I have in my Form class to log output
<code>
delegate void AddOutputItem(string msg);
public void LogOutput(string msg)
{
ListViewItem item = new ListViewItem(msg);
if (this.listView_Output.InvokeRequired)
{
try
{
AddOutputItem d = new AddOutputItem(LogOutput);
this.Invoke(d, new object[] { msg });
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
}
else
{
this.listView_Output.Items.Insert(0, item);
}
}
</code>
The above code seems to work correct until it gets to the Invoke() call.
That is, UI thread calls to LogOutput have InvokeRequired = false and the
calls coming from my Process have it set to true. Once it hits that
Invoke() it hangs. No exceptions, nothing.. jsut stalls out.
Anyone have any ideas? Without exceptions I'm not really sure what to do.
Thanks for reading,
Steve
and basically ended up adapting an MS example to fot my needs. It all made
sense until I tried it
My process makes calls to a Singleton logger class which in turn makes calls
to a delegate to add items to a listbox in my WinForm.
Here is the code that I have in my Form class to log output
<code>
delegate void AddOutputItem(string msg);
public void LogOutput(string msg)
{
ListViewItem item = new ListViewItem(msg);
if (this.listView_Output.InvokeRequired)
{
try
{
AddOutputItem d = new AddOutputItem(LogOutput);
this.Invoke(d, new object[] { msg });
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
}
else
{
this.listView_Output.Items.Insert(0, item);
}
}
</code>
The above code seems to work correct until it gets to the Invoke() call.
That is, UI thread calls to LogOutput have InvokeRequired = false and the
calls coming from my Process have it set to true. Once it hits that
Invoke() it hangs. No exceptions, nothing.. jsut stalls out.
Anyone have any ideas? Without exceptions I'm not really sure what to do.
Thanks for reading,
Steve