S
sklett
I'm fairly new to Threading and things have been going pretty smooth so far.
I did some performance testing on my new app and realized it's lagging a bit
on raising events. It's a realtime app and I need to really make sure that
I'm not falling behind (hence the multi threads) so I determined what was
causing the lag and it's absolutely the events I'm raising and possibly also
the UI work they are doing.
Now, from what I can tell from the framework I'm using (Composite
Application Block) once I'm publishing (raising) the events, they are
handled in the UI thread, but still, I have lag.
Here's my basic situation:
<code>
// class SomeProcessingClass...
public event EventHandler ProcessStarted;
public event EventHandler ProcessComplete;
// the UI calls Something() and Something() starts a thread to run the
lenghtly process...
public void Something()
{
// code to start a new thread and start SomethingProc()
}
public void SomethingProc()
foreach(Item i in items)
{
if(ProcessStarted != null)
ProcessStarted(this, EventArgs.Empty);
DoLongProcess(i);
if(ProcessComplete != null)
ProcessComplete(this, EventArgs.Empty);
}
}
DoLongProcess(Item i)
{
Thread.Sleep(2500);
}
</code>
That was pseudo code, but it's basically what I'm doing. If I comment out
the events, I pretty much hit my real-time performance needs (expect 10
seconds and it actually takes 9.994645)
BUT, I don't want to give up my UI feedback as I'm doing this processing. I
thought that maybe I could increase speed by raising the events on the
thread that Something() was called on rather than SomethingProc() which is
the real performer that needs to not be slowed down by anything.
I can't figure out how to do this.... I don't even know if it's possible.
It seems like any function calls from thread 'B' will execute on thread 'B',
I need to make a call from thread 'B' and make it execute on thread 'A'
Any tips?
Thanks for reading!
Steve
I did some performance testing on my new app and realized it's lagging a bit
on raising events. It's a realtime app and I need to really make sure that
I'm not falling behind (hence the multi threads) so I determined what was
causing the lag and it's absolutely the events I'm raising and possibly also
the UI work they are doing.
Now, from what I can tell from the framework I'm using (Composite
Application Block) once I'm publishing (raising) the events, they are
handled in the UI thread, but still, I have lag.
Here's my basic situation:
<code>
// class SomeProcessingClass...
public event EventHandler ProcessStarted;
public event EventHandler ProcessComplete;
// the UI calls Something() and Something() starts a thread to run the
lenghtly process...
public void Something()
{
// code to start a new thread and start SomethingProc()
}
public void SomethingProc()
foreach(Item i in items)
{
if(ProcessStarted != null)
ProcessStarted(this, EventArgs.Empty);
DoLongProcess(i);
if(ProcessComplete != null)
ProcessComplete(this, EventArgs.Empty);
}
}
DoLongProcess(Item i)
{
Thread.Sleep(2500);
}
</code>
That was pseudo code, but it's basically what I'm doing. If I comment out
the events, I pretty much hit my real-time performance needs (expect 10
seconds and it actually takes 9.994645)
BUT, I don't want to give up my UI feedback as I'm doing this processing. I
thought that maybe I could increase speed by raising the events on the
thread that Something() was called on rather than SomethingProc() which is
the real performer that needs to not be slowed down by anything.
I can't figure out how to do this.... I don't even know if it's possible.
It seems like any function calls from thread 'B' will execute on thread 'B',
I need to make a call from thread 'B' and make it execute on thread 'A'
Any tips?
Thanks for reading!
Steve