R
RSH
Hi,
I have an Asynchronus process that is reporting back to the UI at regular
intervals. I read several posts on how to use delegates to make this
happen. But for some reason my application just hangs, nothing being
written it just hangs. when I comment out the "Invoke(new
UpdateTextCallback(UpdateText));" it works fine.
What am I missing?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
EventMonitor.ProcessMonitor += new ProcessMonitorHandler(DisplayEvents);
Party m_Party = new Party();
}
private void DisplayEvents(object sender, ProcessEventArgs e)
{
if (InvokeRequired)
{
System.Diagnostics.Debug.WriteLine("HIT!");
Invoke(new UpdateTextCallback(UpdateText));
}
else
{
richTextBox1.Text += e.EventArg + "\r\n";
}
Application.DoEvents();
}
private void UpdateText(object sender, ProcessEventArgs e)
{
System.Diagnostics.Debug.WriteLine("HIT!");
richTextBox1.Text += e.EventArg + "\r\n";
}
public delegate void UpdateTextCallback(object sender, ProcessEventArgs e);
public delegate void ProcessMonitorHandler(object sender, ProcessEventArgs
e);
}
public static class EventMonitor
{
public static event ProcessMonitorHandler ProcessMonitor;
public static void BroadcastEvent(string Event)
{
OnEvent(Event);
}
static void OnEvent(string Event)
{
if (ProcessMonitor != null)
{
ProcessEventArgs e = new ProcessEventArgs();
e.EventArg = Event;
ProcessMonitor(null, e);
}
}
}
I have an Asynchronus process that is reporting back to the UI at regular
intervals. I read several posts on how to use delegates to make this
happen. But for some reason my application just hangs, nothing being
written it just hangs. when I comment out the "Invoke(new
UpdateTextCallback(UpdateText));" it works fine.
What am I missing?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
EventMonitor.ProcessMonitor += new ProcessMonitorHandler(DisplayEvents);
Party m_Party = new Party();
}
private void DisplayEvents(object sender, ProcessEventArgs e)
{
if (InvokeRequired)
{
System.Diagnostics.Debug.WriteLine("HIT!");
Invoke(new UpdateTextCallback(UpdateText));
}
else
{
richTextBox1.Text += e.EventArg + "\r\n";
}
Application.DoEvents();
}
private void UpdateText(object sender, ProcessEventArgs e)
{
System.Diagnostics.Debug.WriteLine("HIT!");
richTextBox1.Text += e.EventArg + "\r\n";
}
public delegate void UpdateTextCallback(object sender, ProcessEventArgs e);
public delegate void ProcessMonitorHandler(object sender, ProcessEventArgs
e);
}
public static class EventMonitor
{
public static event ProcessMonitorHandler ProcessMonitor;
public static void BroadcastEvent(string Event)
{
OnEvent(Event);
}
static void OnEvent(string Event)
{
if (ProcessMonitor != null)
{
ProcessEventArgs e = new ProcessEventArgs();
e.EventArg = Event;
ProcessMonitor(null, e);
}
}
}